Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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">
    <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...

like image 371
Craig Avatar asked Sep 06 '25 11:09

Craig


2 Answers

Instead of EditorFor, use TextBoxFor:

<%=Html.TextBoxFor(m => m.Name, new {style = "width:50px"})%>
like image 151
Michael Maddox Avatar answered Sep 08 '25 01:09

Michael Maddox


What's wrong with using CSS to style your control width?

like image 23
Erik Funkenbusch Avatar answered Sep 08 '25 00:09

Erik Funkenbusch