6

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.

rohitreddyk
  • 337
  • 2
  • 15
Metaphor
  • 374
  • 1
  • 5
  • 20

1 Answers1

17

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")
Stefano Magistri
  • 1,130
  • 1
  • 11
  • 18
  • the @ on @maxlength is important. I forgot to include it, and the length limitation was completely ignored. – MeanJerry May 03 '19 at 18:42
  • it shouldn't be required. The @ tells razor to escape from matching c expressions. So if you wanted to add html attribute class you would have to have it, but maxlength shouldn't need it. – John Lord Oct 12 '22 at 16:09