设置 Kendo TextboxFor 最大长度

Set Kendo TextboxFor max length

我想将文本框的最大长度设置为 5,谁能告诉我该怎么做。

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

我试过

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

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

但是如果我使用 .Name,我会在通过模型传入的控制器中得到中间名的空值。

我相信你只需要这样做:

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