Craig Craig - 26 days ago 7
C# Question

MVC and EditorFor width

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">
<%=Html.LabelFor(m => m.Name)%>
<%=Html.EditorFor(m => m.Name)%>

Can this be done somehow?

I tried:

<%=Html.EditorFor(m => m.Name, new {width=50)%>

But no joy...


Instead of EditorFor, use TextBoxFor:

<%=Html.TextBoxFor(m => m.Name, new {style = "width:50px"})%>