2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > mvc html 多行文本框 asp.net-mvc – 如何在MVC3中为多行文本框创建多个编辑器模板?...

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

时间:2023-10-07 05:53:54

相关推荐

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显然应该是不同的.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。