r.r
r.r

Reputation: 7153

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?

Upvotes: 4

Views: 18928

Answers (2)

Shaiju T
Shaiju T

Reputation: 6609

you can also do using css style, its that simple and worked great for me

@Html.TextBoxFor(model => model.UserName, new { style = "width: 250px;" })

got this idea from Darin's answer for DropdownList width.

hope helps someone.

Upvotes: 6

D&#39;Arcy Rittich
D&#39;Arcy Rittich

Reputation: 171351

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;
}

Upvotes: 11

Related Questions