Rendering a <textarea /> using data annotations

serlingpa picture serlingpa · May 16, 2013 · Viewed 13.4k times · Source

I'd like to render a text area for one of the fields in my model.

I've tried applying [DataType(DataType.MultilineText)] to my field, but this doesn't do the trick.

At the moment, I am rendering the text area manually but I'd much prefer to use Html.EditorFor. Any suggestions?

Answer

Leniel Maccaferri picture Leniel Maccaferri · Oct 12, 2013

[DataType(DataType.MultilineText)] only works if you use Html.EditorFor helper in your view:

Sample:

Model

[DataType(DataType.MultilineText)]
public string Description { get; set; }

View

Html.EditorFor(m => m.Description)