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#
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With