John
John

Reputation: 67

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)
</div>

Any suggestions?

Upvotes: 1

Views: 3194

Answers (2)

chirag
chirag

Reputation: 1

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

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

Upvotes: -2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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

[DataType(DataType.MultilineText)]
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)
</div>

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)
</div>

Personally I prefer the first approach.

Upvotes: 10

Related Questions