我有一个选择列表,我将它绑定在ajax后。我想用它代替的DropDownListFor(model=>model...)
如何设置选择列表是为模型作为dropdownlistfor mvc
这里是我的代码:
function GetDateReadingMeter(meterId) {
// GetMeterReadingDates
$.ajax({
type: "POST",
url: '@Url.Action("GetMeterReadingDates", "ApartmentAccrual")',
dataType: "JSON",
data: JSON.stringify({ "meterId": meterId }),
contentType: "application/json",
success: function (data) {
var markup = "<option value='0'>Sayaç Okuma Tarihi Seçiniz</option>";
for (var x = 0; x < data.length; x++) {
markup += "<option value=" + data[x].d + ">" + data[x].d + "</option>";
}
$("#ddlReadingDate").html(markup).show();
}
});
}
在HTML ...
<select class="select1" id="ddlReadingDate" name="ddlReadingDate" style="width: 200px"></select>
// I want to use this select instead of ==>
@Html.DropDownListFor(model => model.MeterAccrualViewModel.SayacTahakkuk.ReadingDate, "", new { type = "text", @class = "select1" })
只是不使用'DropDownListFor'辅助方法。确保您的手形编码SELECT元素具有正确的名称属性值。 – Shyju
为什么在世界上你不想使用'DropDownListFor()'?你让它成为'name =“MeterAccrualViewModel.SayacTahakkuk.ReadingDate”'但这永远不会给你正确的双向模型绑定(并且'new {type =“text”}'不是'