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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.