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?
Try
Html.TextAreaFor(model => model.Description, new {@cols="80" , @rows="4" })
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
-
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With