5

I have an application built in MVC5 with c#. I have 5 dropdowns on my view.

These dropdowns are partialviews. Content of dropdowns:-

1) list of cities

2) list of events.

3) list of venues

4) list of dates

5) list of times

so when page is first loaded the cities are populated. when I select a city, second dropdown is populated with list of events. and now when I select a event the next dropdown is populated with Venues. and the same process happens for all of the dropdowns.(ofcourse there in no change event for times dropdown as it is last).

now there is a submit button when I click this button it redirects me to new page using controllers method. Signature is as follows

public ActionResult Redirect(string hdn_city, string hdn_event, string hdn_date, string hdn_venue, string hdn_time)  
{
    string urls = String.Format("mysite.com?cid={0}&eid={1}&did={2}&vid={3}&tid={4}", hdn_city, hdn_event, hdn_date,hdn_venue,hdn_time);             
    return Redirect(urls);
}

now when I submit this form I am redirected to mysite.com with all the params passed in query string.

Now my problem is that it is required if after reaching mysite.com i press browser back button the values of dropdown should persist. I dont have to repeat the whole process again. Please suggest me possible alternatives.

ekad
  • 14,436
  • 26
  • 44
  • 46
Learner
  • 1,277
  • 3
  • 15
  • 34

2 Answers2

0

You can use Cookie or TempData or History Javascript (Html5 only). Or you can make a PostBack at the end for save value in browser.

You can save only selected values, and reload associate data.

Postback like this: <form action="thispage.aspx?dropdownvalue1=***&dropdownvalue2=**"></form>.

ArDumez
  • 931
  • 6
  • 24
0

The easiest way I could think of would be to use query string to store selected values. E.g. when you select a city, redirect to

/selectionPage?city=selectedCity

Then, when selecting an event, redirect to

/selectionPage?city=selectedCity&event=selectedEvent

And so on. This way you will have all selected values in the query string, so moving back/forward in the browser history will work as is.

  • I put the break point on action method in controller. but when I use browser back button the break point is not hit. – Learner May 19 '15 at 07:42
  • 1
    Because of the browser cache. You could disable that for a specific action (using action attribute, see [here](http://stackoverflow.com/a/1705113/4910910)). But why would you want to do that? If the page is stateless (i.e. the dropdown values are populated based on the query string) then it is OK to have it cached. – Alexandr Sugak May 19 '15 at 08:08
  • Thanks Alexandr Sugak. I think i need to somehow use query string. I am waiting for any solution that can help me to avoid that. – Learner May 19 '15 at 09:48