Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I decorate my ASP.NET MVC ViewModel property to render as a textarea when using EditorForModel()

Tags:

asp.net-mvc

How can I decorate my ASP.NET MVC ViewModel property to render as a textarea when using EditorForModel()

like image 385
Mike Cole Avatar asked Jun 21 '10 03:06

Mike Cole


1 Answers

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>
like image 128
Darin Dimitrov Avatar answered Sep 18 '22 12:09

Darin Dimitrov