creating multiline textbox using Html.Helper function
Solution 1:
A multiline textbox in html is <textarea>
:
<%= Html.TextArea("Body", null, new { cols = "55", rows = "10" }) %>
or:
<%= Html.TextArea("Body", null, 10, 55, null) %>
or even better:
<%= Html.TextAreaFor(x => x.Body, 10, 55, null) %>
And yet another possibility is to decorate your view model property with the [DataType]
attribute:
[DataType(DataType.MultilineText)]
public string Body { get; set; }
and in your view:
<%= Html.EditorFor(x => x.Body) %>
and set the width and height through CSS.
Solution 2:
MVC4 you should use:
@Html.TextAreaFor(x => x.Body, 10, 15, null)
Solution 3:
This allows to multi-line, set custom width and height and setting place holder. For validation used StringLength or RegularExpression in Model.cs
Razor View Syntax
@Html.TextAreaFor(model => model.property, new { style = "width: 420px; height: 100px;", placeholder = "Placeholder here.." })