tags:

views:

24

answers:

2

Title says it all...

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

+1  A: 

Create a text area template and then attribute your VM property with a UIHint("TextArea") attribute.

Ryan
Can you provide a sample or more reference?
Mike C.
http://msdn.microsoft.com/en-us/library/ee308450.aspx
Ryan
+1  A: 

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>
Darin Dimitrov