Search code examples
htmlasp.net-mvchtml-helper

How to set width of html.textboxfor?


I have a <%= Html.TextBoxFor(user => user.Name) %> and it has standart width.

What should I do to make textbox wider?


Solution

  • You can do this to add a CSS class called singleTextBox, and then you can assign a width in your style sheet:

    <%= Html.TextBoxFor(model => model.UserName, new { @class = "singleTextBox" }) %>
    

    In your style sheet:

    .singleTextBox {
        width: 12em;
    }