Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a size for html.EditorFor helper?

What is the simplest way to set the size of the generated field?

like image 984
marcin Avatar asked Mar 08 '11 16:03

marcin


People also ask

What is the difference between Textboxfor and EditorFor?

it's absolutly wrong answer, becuase the key difference is that Texbox returns input and editorfor returns your template where input is default template for editorfor.

What is HTML EditorFor in MVC?

Create HTML Controls for Model Class Properties using EditorFor() ASP.NET MVC includes the method that generates HTML input elements based on the datatype. The Html. Editor() or Html. EditorFor() extension methods generate HTML elements based on the data type of the model object's property.


1 Answers

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, ...

like image 155
Darin Dimitrov Avatar answered Sep 28 '22 01:09

Darin Dimitrov