0

如果我不使用任何 KendoUI 功能并且能够使用常规的 Html.DropDownListfor 帮助器(在代码中作为注释)轻松传递它,这可以正常工作。Description 和 StatusID 都没有通过。

在下拉列表中选择这些值然后单击带有 KendoUI 扩展的 Enter 后,如何将这些值传递给控制器​​?

如果我取消注释 Value 和 Text 属性,我会得到“对象未设置为对象的实例”。

@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>
4

0 回答 0