Skip to main content

kendo ui dropdownlist mvc update index

@model MvcApplication1.Models.Contract

@{
    MvcApplication1.Models.UserSession userSession = (MvcApplication1.Models.UserSession)Session["userSession"];
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="form-group">
        @Html.LabelFor(model => model.CType, new { @class = "control-label col-sm-4" })
        <div class="col-sm-8 col-md-6">
            @(Html.Kendo().DropDownListFor(model => model.CType)
                    .Name("CTypeID")
                    )
            @Html.ValidationMessage("Please select CType")
        </div>
    </div>
}

<script type="text/javascript">
        try {
            $.getJSON("/api/Company/GetCompany/@userSession.TenantID",
                function (data) {
                    var types = [{ 'ID': '1', 'CType': 'A' },
                        { 'ID': '2', 'CType': 'B' },
                        { 'ID': '3', 'CType': 'C' },
                        { 'ID': '4', 'CType': 'D' },
                        { 'ID': '5', 'CType': 'E' }];

                    var index;
                    $.each(types, function (key, val) {
                        if (val.ID == "@Model.CTypeID") {
                            index = key;
                        }
                    });

                    $('#CTypeID').kendoDropDownList({
                        dataTextField: 'CType',
                        dataValueField: 'ID',
                        dataSource: cancellationTypes,
                        index: index
                    });
                });
                }
        catch (ex) {
            //Log the exception and alert to the end user
            kendoDialogForEndUserAlert("Error", ex, "Error", ["OK"], null);
        }
    });
</script>