0

This works fine if I don't use any KendoUI functionality and am able to pass it easily using a regular Html.DropDownListfor helper (seen as comments in the code). The Description and the StatusID both do not come through.

How can I pass these values to the controller after selecting them in the dropdown list and then clicking enter with the KendoUI extension?

If I uncomment the Value and Text properties, I get "Object not set to an instance of an Object".

@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>
9
  • I have not used the MVC Kendo functionality, only the Web version - but I am pretty sure that the normal MVC DropDownListFor assigns the name of the field so it binds correctly. In Kendo you are manually assigning the name (statusDropDownList). Can you not remove this line and let Kendo name it so binding will be handled automatically?
    – Jack
    Sep 2, 2013 at 2:51
  • I added a change event and the selected value is being properly selected within the js function after getting a reference to the dropdown list. However, how can I place this selected value in the model when I post? If I use the regular DropDownListFor (not Kendo), this whole process works fine.
    – sagesky36
    Sep 2, 2013 at 16:13
  • When I try and post, both the StatusID and Description are null in my Controller when I look at the Status model (stat variable) as below: public ActionResult AddSingleStatus(Status stat)
    – sagesky36
    Sep 2, 2013 at 16:18
  • Trying removing this line: .Name("statusDropDownList")
    – Jack
    Sep 3, 2013 at 16:38
  • If I remove that name, how am I going to get a reference to it in the dropdownlist_change function?
    – sagesky36
    Sep 5, 2013 at 23:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.