1

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&amp;#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?

ojek
  • 9,680
  • 21
  • 71
  • 110

2 Answers2

3

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

Community
  • 1
  • 1
mipe34
  • 5,596
  • 3
  • 26
  • 38
1

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.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57