How can I decorate my ASP.NET MVC ViewModel property to render as a textarea when using EditorForModel()
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>
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