0

in mvc i am binding a drop down like this

@Html.DropDownList("wantedTime", new List<SelectListItem>

                 {                                        
                    new SelectListItem{ Text="select time", Value = "#" },
                    new SelectListItem{ Text="12:00 AM", Value = "00:00"},
                    new SelectListItem{ Text="12:30 AM", Value = "00:30" },
                    new SelectListItem{ Text="01:00 AM", Value = "01:00" })

It is good for the first time to load but next time when the view reloads because of some reason i want to fix the selected value for the drop down that i hold in session.

So how can i fox the selected value for the ddl in MVC for the above scenario.

NoviceToDotNet
  • 10,387
  • 36
  • 112
  • 166

1 Answers1

0

Can you be a little more specific on what you mean by "fix the selected value"? The link that Bill posted is exactly how you would persist the selected value of a drop down list between calls.

If you're holding a value in Session then the proper way to send it off to the view is either put it in the ViewBag or have a property on your view model for the selected value then just set that to what you have in Session.

Is there even a reason why you are keeping this value in Session?