您可以覆盖
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显然应该是不同的.