这是.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})
答案 0 :(得分:1)
我在MVC 4上重现您的示例,我想您应该在css
hepler中转义EditorFor
属性名称,然后才能正常工作。你在这里:
@Html.EditorFor(model => model.xxx, new { size = 20, maxLength = 10 , @css = "test" })