加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 如何使用EditorForModel()来装饰我的ASP.NET MVC

发布时间:2020-12-16 00:31:11 所属栏目:asp.Net 来源:网络整理
导读:当使用EditorForModel()时,如何将ASP.NET MVC ViewModel属性装饰为textarea 解决方法 您可以使用 [DataType(DataType.MultilineText)] 属性来装饰模型属性: 模型: public class MyModel{ [DataType(DataType.MultilineText)] public string MyProperty {
当使用EditorForModel()时,如何将ASP.NET MVC ViewModel属性装饰为textarea

解决方法

您可以使用 [DataType(DataType.MultilineText)]属性来装饰模型属性:

模型:

public class MyModel
{
    [DataType(DataType.MultilineText)]
    public string MyProperty { get; set; }
}

控制器:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View(new MyModel());
    }
}

视图:

<%@ 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读