Search code examples
asp.net-mvckendo-asp.net-mvc

Set Kendo TextboxFor max length


I want to set max length to 5 for textbox, Can anyone please let me know how to do that.

@(Html.Kendo().TextBoxFor(m => m.LstPreEmploymentWorkflowModel.MiddleInitial))

I tried doing

@(Html.Kendo().TextBoxFor(m => m.LstPreEmploymentWorkflowModel.MiddleInitial).Name("middlenm")

$("#firstnm").attr('maxlength','5');

But if I use .Name, I get null value for middle name in the controller passed in through a model.


Solution

  • I beleive you need only do this:

    @Html.Kendo().TextBoxFor(m => m.LstPreEmploymentWorkflowModel.MiddleInitial)
        .HtmlAttributes(new { style = "width:50px", @maxlength = "5" }).Name("middlenm")