Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 that property of my Model. Descriptino is a 1000 character string. I need the user to be able to enter several lines of text and have it wrap in the HTML object. How do I do this?

like image 410
MikeTWebb Avatar asked Oct 25 '11 19:10

MikeTWebb


3 Answers

Try

Html.TextAreaFor(model => model.Description, new {@cols="80" , @rows="4" })
like image 199
jperez Avatar answered Oct 19 '22 17:10

jperez


Use:

@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"

Notice: you can use null instead of new { } for htmlAttributes but it is not recommended! It's strongly recommended that use a blank new { } -that represents a new object-

like image 36
amiry jd Avatar answered Oct 19 '22 17:10

amiry jd


You can use EditorFor, but in that case it's better to define your own EditorTemplate for rendering your TextArea, using TextAreaFor or whatever it's needed.

The main difference between the TextAreaFor and EditorFor is that, if I've understood well how everything works, when using EditorFor, Templates are taken into account, while when using TextAreaFor you choose the HTML Input used for rendering.

Templates seems interesting, I'm just starting digging into writing my own.

like image 1
BigMike Avatar answered Oct 19 '22 19:10

BigMike