Reputation: 79
What is the simplest way to set the size of the generated field?
Upvotes: 7
Views: 13257
Reputation: 12730
Another option still: rather than appending the class to the wrapper around your input, you can apply HTML properties to the input itself (doesn't work for "EditorFor" though):
@Html.TextBoxFor(x => x.Foo, new { @class = "bar" })
Further discussion: http://michaelware.net/post/2010/01/31/Custom-Attributes-When-Using-HtmlTextBoxFor.aspx
Upvotes: 6
Reputation: 1039408
Using CSS:
<div class="foo">
<%= Html.EditorFor(x => x.Foo) %>
</div>
and in your CSS file:
.foo input {
width: 200px;
}
You could also implement a custom DataAnnotationsModelMetadataProvider which would allow you to attach any attributes you like to the generated input field such as class
, maxlength
, size
, ...
Upvotes: 15