Title says it all...
How can I decorate my ASP.NET MVC ViewModel property to render as a textarea when using EditorForModel()
Title says it all...
How can I decorate my ASP.NET MVC ViewModel property to render as a textarea when using EditorForModel()
Create a text area template and then attribute your VM property with a UIHint("TextArea")
attribute.
You could decorate the model property with the [DataType(DataType.MultilineText)]
attribute:
Model:
public class MyModel
{
[DataType(DataType.MultilineText)]
public string MyProperty { get; set; }
}
Controller:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyModel());
}
}
View:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SomeNs.Models.MyModel>" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%: Html.EditorForModel() %>
</asp:Content>