B. Rajput
B. Rajput

Reputation: 11

How to retain values of dropdown with selected values in MVC?

The scenario is - There are two view in my mvc application. One is Index and other is for adding payment details. in index form I fetch details of a perticular client in that I have cascading dropdown one for selecting type and one for according to type select client in another dropdown, both are coming from DB's and on d same view I have an ActionLink for going on Payments view "for adding the payment details for the same client that is been selected on Index views second dropdown (first is for Type)".

My problem is that when I am going on Payments view and clicking back button of browser to go back on my index page it is clearing the second dropdown. and all other data is safe on the form. So can you please help me to avoid this so that all the data of my Index view should retain throughout the execution.

This also in case when I add Payment for that client and click submit it should redirect on the Index view with retaining all its previous data. that we have fetched on Index page. with a message box Payment Added successfully.

Upvotes: 1

Views: 603

Answers (1)

Minh Nguyen
Minh Nguyen

Reputation: 2201

You can save the current selected values of dropdown1 and dropdown2 into one of the followings:

  • URL
  • Session
  • Cookie

Then in the Index page you always check to read those values if they are existed to setup the dropdowns in the first request. Then do update those values again whenever user selects to update the dropdowns.

Upvotes: 1

Related Questions