【发布时间】:2015-10-29 08:17:54
【问题描述】:
这是我在.cshtml 中的代码。我想将 css 的值传递给我的自定义编辑但不工作。
@Html.EditorFor(model => model.xxx, new { size = 20, maxLength = 10 , css = "test" })
我的代码在自定义编辑中。
@model string
@{
int size = 50;
int maxLength = 50;
string type = "text";
string css = "";
if (ViewData["size"] != null)
{
size = (int)ViewData["size"];
}
if (ViewData["maxLength"] != null)
{
maxLength = (int)ViewData["maxLength"];
}
if (ViewData["type"] != null)
{
type = (string)ViewData["type"];
}
if (ViewData["css"] != null)
{
css = (string)ViewData["css"];
}
}
@Html.TextBox("", Model, new { Size = size, MaxLength = maxLength, Type = type, @class = css})
【问题讨论】:
-
你使用什么版本的 MVC?而你的
model.xxx是string类型? -
是的,它是一个字符串类型。换个标签
标签: asp.net-mvc razor asp.net-mvc-5