简体   繁体   中英

kendo ui dropdownList Disable

I am working with kendo ui with asp.net mvc 5. I have some condition where I have to show the kendo ui dropdownlist disabled, but when I submit the from (post) the model field which I have used to bind the drop-down list contains null instead of value.

Here is my code:

@(Html.Kendo().DropDownListFor(i => i.CallTypeId)
    .Name("CallTypeId")
    .HtmlAttributes(new { style = "width:100%" })
    .DataTextField("MasterValueName")
    .DataValueField("MasterValueId")
    .Enable(false)
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetCallType", "Common", new { Area = "" });
        });
    })
    .OptionLabel("Select Call Type")
)

Is there any other alternate to disable the kendo dropdownlist but remember I need the selected value. Thanks In advance.

You don't receive the value because your control is disabled.

According to this answer all disabled elements are not passed to form processor.

I think that you have to use the ReadOnly method instead of Enable .

If you are posting the form with JavaScript (or have that option), you can enable the field just before posting so that the model contains the value:

View:

@(Html.Kendo().Button()  // hidden post button to be "clicked" from JavaScript
    .Name("btnPostForm")
    .HtmlAttributes(new { type = "submit", style = "display:none", name = "Command" })
)

Script:

// Enable the drop-down.
$('#CallTypeId').getKendoDropDownList().enable(true);

// Post the form.
var postButton = $('#btnPostForm');
postButton.attr('value', 'SaveForm');  // optional command name for controller to read
postButton.click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM