kendo ui dropdownlist mvc update index

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>



ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^