mvc html 多行文本框,asp.net-mvc – 如何在MVC3中为多行文本框创建多个编辑器模板?...

您可以覆盖

default editor template(〜/ Views / Shared / EditorTemplates / MultilineText.cshtml):

@Html.TextArea(

"",ViewData.TemplateInfo.FormattedModelValue.ToString(),ViewData

)

然后假定您已经定义了一个视图模型:

public class Myviewmodel

{

[DataType(DataType.MultilineText)]

public string Text { get; set; }

}

在主视图内可以做到这一点:

@model Myviewmodel

@Html.EditorFor(x => x.Text,new { cols = "100",rows = "15",id = "dialogText",@class = "full-width" })

@Html.EditorFor(x => x.Text,rows = "10",@class = "full-width" })

这将使预期产出:

hello world

hello world

此外,您可以增强编辑器模板,以便您不需要在每个EditorFor调用中指定@class属性,如下所示:

@{

var htmlAttributes = ViewData;

htmlAttributes["class"] = "full-width";

}

@Html.TextArea(

"",htmlAttributes

)

现在你可以:

@model Myviewmodel

@Html.EditorFor(x => x.Text,id = "dialogText" })

@Html.EditorFor(x => x.Text,id = "dialogText" })

哦,不要忘记,ids在HTML中必须是唯一的,所以这个id =“dialogText”对于第二个textarea显然应该是不同的.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值