asp.net mvc - MVC Dropdown list value not being set -
I'm sure I'm missing something clearly, but this is driving me crazy! If I specify the HTML option, the value of my dropdown list is not set.
In my Controller, I retrieve this option for my dropdown list:
ViewData ["coordinator"] = New selection list (User repository. GetIDUser list (1 ), "Id", "signature", edcenter.coordinator);
In my opinion, I populate the dropdown list with:
Html.DropDownList "Coordinator", (IEnumerable) View Data ["Coordinator"], New {style = " Width: 175px "}) The dropdown values are fully populated, but the price of the list is not selected
However, if I currently use:
Html.DropDownList ("Coordinator"); Everything works fine
What's going wrong?
I was battling this kind of problem yesterday so if you are still getting the same result So one more thing to consider is DropDownList sometimes neglects the selected value of your SelectList, it is annoying but what does it do, using model name as a key, model value, value and model selected value Attempts to obtain. In your case you are storing the list in the ViewData ["Coordinator"], the key is the same name as the dropdown: Try it:
See data ["coordinator list"] = new selection list ( User Repository.GetIDUser List (1), "ID", "Signature", edCenter.Coordinator); See data ["coordinator"] = deconcenter Chordinator; Then in the scene:
& lt;% = html.DropDownList (see "coordinator", (selector) data ["coordinator list"]) Asenumerable (), new {style = "width: 175px"})%> If you want to see what is going on behind the reflections that open the prescription (or get the MVC source) and browse this method: System.Web.Mvc.Html. SelectExtensions.SelectInternal ()
Comments
Post a Comment