MVC3 HTML Helper for Large Text Area

I have an html helper:

@Html.EditorFor(model => model.Description)

But it is too small for the data in this property of my model. Descriptino is a string with 1000 characters. I need the user to be able to enter multiple lines of text and wrap it in an HTML object. How to do it?

+5
source share
4 answers

Try

Html.TextAreaFor(model => model.Description, new {@cols="80" , @rows="4" })
+25
source

Using:

@Html.TextAreaFor(model => model.Description)

// or a full option-list is:
@Html.TextAreaFor(model => model.Description, 
    rows, // the rows attribute of textarea for example: 4
    columns, // the cols attribute of textarea for example: 40
    new { }) // htmlAttributes to add to textarea for example: @class = "my-css-class"

Note: you can use nullinstead new { }for htmlAttributes, but this is not recommended! It is highly recommended that you use a space new { }that represents a new object-

+6
source

EditorFor, EditorTemplate TextArea, TextAreaFor , .

The main difference between TextAreaForand EditorForis that, if I understand how everything works, when using the editor, the templates are taken into account, and when using, TextAreaForyou select the HTML input to use for rendering.

Templates seem interesting, I'm just starting to delve into writing my own.

+1
source

It looks like you're after Html.TextAreaFor .

0
source

All Articles