Reputation: 10056
I have something like this:
@Html.TextBoxFor(model => model.Message)
With message being declared like that:
[Required]
[DataType(DataType.MultilineText)]
[Display(Name = "Message", ResourceType = typeof(NameResources))]
[StringLength(256, ErrorMessageResourceName = "MailBoxMessageLengthError", ErrorMessageResourceType = typeof(NameResources), MinimumLength = 2)]
public string Message { get; set; }
And still, i get output like this:
<input data-val="true" data-val-length="Wiadomość nie może przekraczać 256 znak&#243;w" data-val-length-max="256" data-val-length-min="2" data-val-required="Pole Wiadomość jest wymagane." id="Message" name="Message" type="text" value="" />
Why it gives me text input when i clearly want that textbox in there?
Upvotes: 1
Views: 5141
Reputation: 28611
The problem is that you're using
@Html.TextBoxFor
as confirmed by mipe34 this specifically states you want a textbox (single line) not a text area (multi-line).
If you had used
@Html.EditorFor
then MVC will look at your attributes and render the correct control accordingly - you already have [DataType(DataType.MultilineText)]
which would have generated a textarea if you had used EditorFor.
In otherwords: always use EditorFor+attributes or use the correct xFor and don't bother with attributes.
Upvotes: 1
Reputation: 5666
I do not understand what's wrong. <input type="text" />
is actually HTML text box.
If you want multiline "textbox" use Html.TextArea
instead. Good resource on SO, how to use it : creating multiline textbox using Html.Helper function
Upvotes: 3