ASP.NET MVC3 - Textarea With @Html.EditorFor
Answer :
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)
Comments
Post a Comment