How to set the width of the text box when using Html.TextBoxFor

后端 未结 6 1265
走了就别回头了
走了就别回头了 2021-02-01 02:20

I have the following line in my view:

<%= Html.TextBoxFor(m => m.Description)%>
相关标签:
6条回答
  • 2021-02-01 02:49

    A reusable solution is to set the width in your css file

    .wide
    {
         width: 300px;
    }
    

    then set it using the markup above

    <%= Html.TextBoxFor(m => m.Description, new { @class= "wide" })%> 
    
    0 讨论(0)
  • 2021-02-01 02:55

    This worked for me for the one-offs, pretty verbose though:

    <%: Html.TextBoxFor(m => m.Description, new { style="width:50px;" })%>
    
    0 讨论(0)
  • 2021-02-01 02:55

    To me it worked by adding the "input" in the CSS for @Html.TextBoxFor:

    CSS:

    .campoTexto input {
        width: 50px;
    }
    

    For:

    <div class="campoTexto">
    @Html.TextBoxFor(model => model.nombre)
    </div>
    
    0 讨论(0)
  • 2021-02-01 03:07

    You can do also like this

      @Html.TextBoxFor(model => model.Email, new Dictionary<string, object>() { { "readonly", "true" }, { "style", "width:250px;" } })
    
    0 讨论(0)
  • 2021-02-01 03:07

    Just use the properties like "TextBoxFor,TextArea" etc instead of "EditorFor"... Lot of people when use scaffolding, they have to change the fields by themselves or data annotations for in model like [DataType(Multiline)]

    0 讨论(0)
  • 2021-02-01 03:15

    You can attach it as an attribute. Try this:

    <div class="editor-field">
         <%= Html.TextBoxFor(m => m.Description, new { style = "width:20em;" })%>                     
    </div>
    
    0 讨论(0)
提交回复
热议问题