这有效
@Html.DropDownListFor(model => Model.Assessment.Interviewer, Model.SiteListing)
这不是
<div class="resident-relationship">@Html.DropDownListFor(m => Model.HouseholdMembersListing.ElementAt(i).Relationship, Model.ResidentTypeListing, new { @class = "t150"})</div>
如何正确使用@HTML.DropdownListFor绑定到List&lt; 任何&gt;所以在POST到控制器它会有价值?我有一个页面,家里可以有很多居民。我有其他绑定,如姓名和年龄,他们运作良好。但是在关系上我需要有下拉列表。
答案 0 :(得分:0)
var ddlStates = '#dropdownlistId'
$.ajax({
cache:false,
type: "GET",
url: "@(Url.Action("GetStatesByCountryId", "Country"))",
data: "countryId=" + selectedItem + "&addEmptyStateIfRequired=true",
success: function (data) {
ddlStates.html('');
$.each(data, function(id, option) {
if( option.name=="Maharashtra")
{
ddlStates.append($('<option></option>').val(76).html(option.name));
}
});
},
error:function (xhr, ajaxOptions, thrownError){
alert('Failed to retrieve states.');
statesProgress.hide();
}
});