Specify size and maxlength for Html.Kendo().TextBoxFor

Metaphor picture Metaphor · Sep 3, 2015 · Viewed 15.7k times · Source

I am using Server Side Validation On ASP.NET MVC Kendo UI. On a view(used to create) for a text field like this:

@Html.Kendo().TextBoxFor(model => model.CompanyTypeName).Name("CompanyTypeName")

I need to change the size of textbox. I tried like this:

@Html.Kendo().TextBoxFor(model => model.CompanyTypeName, new { style = "width:50px", @maxlength = "5" }).Name("CompanyTypeName")

But doesn't work.Thanks in Advance.

Answer

Stefano Magistri picture Stefano Magistri · Sep 3, 2015

This is only valid using a default textbox.

@Html.TextBoxFor(model => model.CompanyTypeName, new { style = "width:50px", @maxlength = "5" })

This is what you can do:

@Html.Kendo().TextBoxFor(model => model.CompanyTypeName).HtmlAttributes(new { style = "width:50px", @maxlength = "5" }).Name("CompanyTypeName")