Sim*_*tes 4 c# asp.net-mvc html-helper
我想将htmlAttributes作为一个object类似的方法传递给...
foo.HtmlAttributes(new { data_bind = "foo"});
Run Code Online (Sandbox Code Playgroud)
在所有的MVC HtmlHelpers中,我使用下划线作为连字符,这将输出有效的html "data-bind"
在幕后,这是根据以下问题进行的:
public virtual void HtmlAttributes(object htmlAttributes)
{
this.Attributes = new RouteValueDictionary(htmlAttributes);
}
Run Code Online (Sandbox Code Playgroud)
后来这将被称为:
internal virtual void ApplyConfiguration(TagBuilder tag)
{
tag.MergeAttributes(this.Attributes);
}
Run Code Online (Sandbox Code Playgroud)
但是这会输出:
<div data_bind="foo"></div>
Run Code Online (Sandbox Code Playgroud)
如何输出有效的HTML?
更新 感谢Zabavsky ......
public virtual void HtmlAttributes(object htmlAttributes)
{
this.Attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1347 次 |
| 最近记录: |