如果我不使用任何KendoUI功能并且能够使用常规Html.DropDownListfor帮助程序轻松传递它(在代码中看作注释),这可以正常工作。描述和StatusID都没有通过。
如何在下拉列表中选择这些值并将其与KendoUI扩展名一起输入后,将这些值传递给控制器?
如果我取消注释Value和Text属性,我会得到“Object not set to Object of instance”。
@using (Html.BeginForm("AddSingleStatus", "Status", new AjaxOptions { HttpMethod = "POST", }))
{
@Html.ValidationSummary(true)
<table>
<tr>
<td>
<div class="display-label">
@Html.LabelFor(model => Model.Description);
</div>
<div class="display-label" style="display: none;">
@Html.HiddenFor(model => Model.Description)
</div>
<div class="editor-field">
@(Html.Kendo().DropDownListFor(model => Model.StatusID)
.Name("statusDropDownList")
.DataTextField("Description")
.DataValueField("StatusID")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("ReadDDL", "Status");
})
.ServerFiltering(false);
})
.OptionLabel("Select a status")
.SelectedIndex(0)
.Events(e => e
.Change("dropdownlist_change")
)
)
@* @Html.DropDownListFor(model => Model.StatusID, new SelectList((YeagerTechModel.Status[])ViewData["statuses"], "StatusID", "Description"));*@
@*@Html.ValidationMessageFor(model => Model.StatusID)*@
</div>
</td>
</tr>
<tr>
<td>
<input type="submit" id="ddlSubmit" value='@Resources.Add' />
</td>
</tr>
</table>
}
<script type="text/javascript">
function dropdownlist_change()
{
var dropdownlist = $("#statusDropDownList").data("kendoDropDownList");
dropdownlist.bind("change", function (e)
{
var value = dropdownlist.value();
});
}
</script>