user1137472
user1137472

Reputation: 345

TextBoxFor Mulitline

Hi people I have been at this for like 5 days and could not find a solution am trying to get this to go on multi line @Html.TextBoxFor(model => model.Headline, new { style = "width: 400px; Height: 200px;"})but I have had no luck.

The following is what I tried:

@Html.TextBoxFor.Multiline (does not work)

I have put Multiline on the end of new and that has not worked. What is the simplest way of doing this.

Thank You I am using MVC3 C#

Upvotes: 12

Views: 30935

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038800

You could use a TextAreaFor helper:

@Html.TextAreaFor(
    model => model.Headline, 
    new { style = "width: 400px; height: 200px;" }
)

but a much better solution is to decorate your Headline view model property with the [DataType] attribute specifying that you want it to render as a <textarea>:

public class MyViewModel
{
    [DataType(DataType.MultilineText)]
    public string Headline { get; set; }

    ...
}

and then use the EditorFor helper:

<div class="headline">
    @Html.EditorFor(model => model.Headline)
</div>

and finally in your CSS file specify its styling:

div.headline {
    width: 400px;
    height: 200px;
}

Now you have a proper separation of concerns.

Upvotes: 55

Related Questions