monica73174
asked on
dropdownlistfor not selecting value
I have a dropdown list in an MVC 5 razor view. My model is passing through the correct value but the value is never selected in the list. I am not sure what else I can do?
Model
View
Model
[DisplayName("State/Province")]
public Nullable<int> state_province_id { get; set; }
View
<div class="form-group">
@Html.LabelFor(m => addy.state_province_id, new { @class = "control-label col-md-3" })
@Html.DropDownListFor(m => addy.state_province_id, item.state_province_dropdown, "-- Select --", new { @class = "form-control" })
</div>
ASKER
Thanks for the suggestion but that just throws an error in Visual Studio.
Check whether it has value or not.
@Html.DropDownListFor(m => addy.state_province_id, item.state_province_dropdown.HasValue ? item.state_province_dropdown.Value : null, "-- Select --", new { @class = "form-control" })
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this
Open in new window