html5 - Dropdownlistfor will not show the correct selection -
I have three dropdown lists in the loop, which do not show the correct value from DB. They are always the default for the first entry. I have checked and double checked DB and verified that it should be second in the list. The list is also well-formed. What am I missing
@foreach (Customer.MeasurementProfile in Model.Customer.CustomerMeasurementProfiles.Where OProfile (M = & gt; m.DeletedDate == faucet))? {& Lt; Div class = "valuesforoneprofile form-group form-group-tight col-md-2" & gt; & Lt; Div class = "col-md-11" & gt; @ Html.Hidden (String.Format ("Customer.CustomerMeasurementProfiles [{}} .eid", i), oProfile.Id) @ Html.Hidden (String.Format ("Customer.CustomerMeasurementProfiles [{}.] Customer ID "I," Opfile.CustomerID @html textbox (string.format ("Customer. Customer Measurement Profile [{}} .name", I), Opfil .name, new {@ class = "form-control input- SM "{}}
If you want to set the selected value that is model . You need to do this like this:
@ Html.DropDownListFor (M = & gt; oProfile.BodyTypeShoulderId, new selectList (Model.BodyTypeShoulders, "id", "name", OProfile.BodyTypeShoulderId), new {@class = "form-control input-sm-select"})
The above code dropdown values the selected model object The first argument of bodytip shelter id
dropdown list
indicates that the selected drop down down on the form will be mapped to the model property that is set there (We m => oProfil E.BodyTypeShoulderId
) but this selected value is not set.
To set the selected value, you have to pass the SelectList
fourth parameter, which is the object selected
Comments
Post a Comment