You could use the [DataType]
attribute on your view model like this:
public class MyViewModel
{
[DataType(DataType.MultilineText)]
public string Text { get; set; }
}
and then you could have a controller:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyViewModel());
}
}
and a view which does what you want:
@model AppName.Models.MyViewModel
@using (Html.BeginForm())
{
@Html.EditorFor(x => x.Text)
<input type="submit" value="OK" />
}
Someone asked about adding attributes (specifically, 'rows' and 'cols'). If you're using Razor, you could just do this:
@Html.TextAreaFor(model => model.Text, new { cols = 35, @rows = 3 })
That works for me. The '@' is used to escape keywords so they are treated as variables/properties.
@Html.TextAreaFor(model => model.Text)
Declare in your Model with
[DataType(DataType.MultilineText)]
public string urString { get; set; }
Then in .cshtml can make use of editor as below. you can make use of @cols and @rows for TextArea size
@Html.EditorFor(model => model.urString, new { htmlAttributes = new { @class = "",@cols = 35, @rows = 3 } })
Thanks !
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