MVC 2 EditorForModel defines the width of the generated input

I use Html.EditorForModel()in the view to create fields for the edit form. I also have another incomplete class where I specify some Data Annotation attributes for some fields (e.g. DisplayName, Range, etc.).

When I launch the application, I have HTML inputs created for each field. How to specify the width of these generated inputs?

Something like that:

<input id="nameTextBox" style="width:220px" name="theName" />
+3
source share
2 answers
Decision

@Gerrie works, but it applies to all the inputs on the page. If you have other inputs on the page that you do not want to set this way, you can do something like this:

<div id="model-editor">
    <%: Html.EditorForModel() %>
</div>

CSS :

#model-editor input { width:220px; }

CSS , . HTML id, :

input[id='YourInputId'] { width:400px; }
+2

CSS:

input
{
    width: 220px;
}

, .

+1

Source: https://habr.com/ru/post/1774526/


All Articles