Can I set the width of an EditorFor control on my View?
I have set a few parameters:
[Required, DisplayName("Payee Name"), StringLength(50)]
public string Name { get; set; }
However, I can't seem to set the width of the textbox that gets rendered.
<table width="300" border="0" cellpadding="3" cellspacing="0">
<tr>
<td>
<%=Html.LabelFor(m => m.Name)%>
</td>
<td>
<%=Html.EditorFor(m => m.Name)%>
</td>
</tr>
Can this be done somehow?
I tried:
<%=Html.EditorFor(m => m.Name, new {width=50)%>
But no joy...
Above answer Yes and No. We need to use develop tool to check what styles used and modify them, they may have max-width, width; Then create own !important css to apply it, my case:
see attached image result.
enter image description here
If you need a custom width outside of a normal CSS rule and you are using Editor Templates you can do
Then in your editor template for String add this to your template
In mvc 5 there is setting in site.css that sets the max-width=200 for all textareas. That confused me until i found this blogpost. http://weblogs.asp.net/paullitwin/visual-studio-2013-asp-net-mvc-5-scaffolded-controls-and-bootstrap as Paul Litwin puts it:
So you if you are a pragmatic you change the max-width to eg 600px
For ASP.NET Core:
With BootStrap 3
Replace
<%=Html.EditorFor(m => m.Name, new {width=50)%>
for this