I use the Html.EditorForModel()
in a view to generate fields for the edit form. I also have another partial class where I specify some Data Annotation attributes for some fields (like DisplayName, Range etc).
When I run the application I have HTML inputs generated for each field. How can I specify the width of t开发者_JAVA技巧his generated inputs ?
Something like this:
<input id="nameTextBox" style="width:220px" name="theName" />
@Gerrie's solution works, but it applies to all inputs on the page. If you have other inputs on the page that you don't want to style this way, then you can do something like this:
<div id="model-editor">
<%: Html.EditorForModel() %>
</div>
And then use CSS of this form:
#model-editor input { width:220px; }
EDIT
If you want to set CSS rules for individual fields, you can do so too. Inspect the generated HTML and find the input's id
, then do:
input[id='YourInputId'] { width:400px; }
use CSS:
input
{
width: 220px;
}
This way you don't have to bother about inserting these style attributes into the generated controls.
精彩评论