Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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#

like image 359
user1137472 Avatar asked Jan 09 '12 20:01

user1137472


Video Answer


1 Answers

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.

like image 98
Darin Dimitrov Avatar answered Sep 24 '22 12:09

Darin Dimitrov