我已将以下行添加到我的 View 中
@Html.EditorFor(model => model, new { htmlAttributes = new { @class = "form-control" }, })
如何在相应的 EditorTemplate Razor View 中访问 htmlAttributes?
另外,如何向 EditorTemplate View 中现有的传入 htmlAttributes 添加一些值?
最佳答案
您可以从 ViewData
中获取它们:
@{
var htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(ViewData["htmlAttributes"]);
htmlAttributes.Add("key", "value"); //add new value
}
关于c# - htmlAttributes MVC 5.1 编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22074432/