0

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.

Guillaume
  • 844
  • 7
  • 25
R K Sharma
  • 845
  • 8
  • 23
  • 42

2 Answers2

2

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.

Community
  • 1
  • 1
Guillaume
  • 844
  • 7
  • 25
0

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();
Tawab Wakil
  • 1,737
  • 18
  • 33