Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify the columns and rows of a multiline Editor-For in ASP.MVC?

In ASP.MVC 3, how do I specify the columns and rows for a multiline EditorFor (textarea)? I am using [UIHint("MultilineText")], but can't find any documentation on how to add attributes for the text area.

Desired HTML:

 <textarea cols="40" rows="10"></textarea> 

Relevant Part of my MVC 3 Model:

[UIHint("MultilineText")] public string Description { get; set; } 

Relevant Part of my Razor cshtml:

<div class="editor-field">     @Html.EditorFor(model => model.Description) </div> 

What I'm getting in View Source:

 <div class="editor-field">      <textarea class="text-box multi-line" id="Description" name="Description"></textarea>  </div> 

How do I set rows and columns?

like image 314
Dan Sorensen Avatar asked Jun 02 '11 17:06

Dan Sorensen


1 Answers

Use TextAreaFor

@Html.TextAreaFor(model => model.Description, new { @class = "whatever-class", @cols = 80, @rows = 10 }) 

or use style for multi-line class.

You could also write EditorTemplate for this.

like image 76
amit_g Avatar answered Oct 09 '22 19:10

amit_g