Changing the size of Html.TextBox

I’m developing an ASP.NET MVC3 application using the new Razor view engine but I’m having some difficulty changing a TextBox so that it is multiline.
So far all I’ve been able to find via google is that I need to set the multiline property to true, but I’m not sure how.

View code looks like this.

<div class="editor-field">
@Html.TextBoxFor(model => model.Body)

Any suggestions?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You could decorate the Body property on your view model with the [DataType] attribute:

public string Body { get; set; }

and in your view use the EditorFor helper instead of TextBoxFor:

<div class="editor-field">
    @Html.EditorFor(model => model.Body)

Another possibility is to leave the model as is without adding any attributes to it and in your view use the TextAreaFor helper:

<div class="editor-field">
    @Html.TextAreaFor(x => x.Body)

Personally I prefer the first approach.

Solution 2

This is how to curve the corners of the textbox in mvc4:

@HTML.TextBoxFor(Model => Model.Name)

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply