asp.net-mvc How to change width Html.TextBox

前端 未结 5 1467
遥遥无期
遥遥无期 2020-12-31 01:25

how do you change the width of a textbox in an asp.net-mvc View

i want to have these fields side by side and the state textbox much shorter width

            


        
相关标签:
5条回答
  • 2020-12-31 02:03
    <%= Html.TextBox("state", null, new { @style = "width: 300px;" })%>
    
    0 讨论(0)
  • 2020-12-31 02:06

    You can use the TextBox helper to add any arbitrary attibutes to your textbox. For instance:

    
    <%= Html.TextBox( "state", null, new { size = "10" } ) %>
    

    Will render something like:

    
    <input type="text" name="state" size="10" />
    
    0 讨论(0)
  • 2020-12-31 02:09

    If using the default MVC template that ships with VS. Explictly specifying a class in the html attributes of the textbox doesn't seem to override Site.css, however, an inline style does work. So:

    {@style= "width: 400px;"} 
    

    will work, whereas this wont:

    {@class="myclass"}
    
    0 讨论(0)
  • 2020-12-31 02:15

    css

    .yourcssclassname{width:50px;}
    

    html

    <%= Html.TextBox("city", null, new{@class="yourcssclassname"})%>
    

    that should do it... you could also obviously send along a style attribute, but css classes are a better path to choose.

    string.Empty represents the default value.

    Edit: see tvanfosson's post

    fixed answer so it solves the problems mentioned in the comments.

    0 讨论(0)
  • 2020-12-31 02:22

    I would use the helper signature that takes HTML attributes and assign it a CSS class. You would then use CSS to achieve the desired look and feel.

     <%= Html.TextBox( "state", null, new { @class = "small-input" } ) %>
    
    0 讨论(0)
提交回复
热议问题