我有一个问题,尝试添加自定义HTML5数据属性到使用WebGrid助手呈现的表。我想要的表标签看起来如下:
<table data-test="testdata"><!-- Table Content --></table>
以下是使用Razor视图引擎的示例视图:
@{ var myUser = new { Id = 1,Name = "Test User" }; var users = new[] { myUser }; var grid = new WebGrid(users); } @grid.GetHtml(htmlAttributes: new { data-test = "testdata"})
最后一行将生成“无效的匿名类型成员声明器”。错误,因为在数据测试中的连字符。
使用一些其他输入HtmlHelpers,您可以使用下划线代替连字符,并且在渲染时将自动更改为连字符。这不会发生在WebGrid。
如果我传入htmlAttributes的字典:
@grid.GetHtml(htmlAttributes: new Dictionary<string,object> {{ "data-test","testdata"}})
表格被呈现如下:
<table Comparer="System.Collections.Generic.GenericEqualityComparer`1[System.String]" Count="1" Keys="System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Object]" Values="System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]"><!-- Table Content --></table>
我做错了什么,我应该做什么渲染所需的属性?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。