WebGrid 中的复杂类型
令人惊讶的是,我在过去 3 小时一直在互联网上搜索如何从作为数据源的复杂类型绑定 webgrid 列。但我找不到任何有用的信息。 有一个关于 MVC 3 中的复杂 WebGrid 绑定 的主题,但没有在我的场景中工作。
为了简化它,假设我有一个 Employee 对象列表,我从中填充 WebGrid,每个 Employee 都有 Address 属性,该属性是 Address 类型。
我想在 WebGrid 中显示“地址”字段的“城市”属性以及“员工”的其他字段。
我认为 grid.Column("Address.City") 可以工作,但事实并非如此。这是不支持的事情,还是我做错了什么。
感谢您的帮助。
问候
无政府主义者极客
I have, surprisingly, been searching on the internet how to bind a webgrid column from a complex type that is data source last 3 hours. But I could not find any useful information.
there is a topic on Complex WebGrid Binding in MVC 3, but it did not work in my scenario.
To simplify it, let's say I have a list of Employee objects that I populate WebGrid from, each Employee have Address property which is Address type.
I would like to show the City property of Address field in the WebGrid along with other fields of Employee.
I assumed that grid.Column("Address.City") would work, but it does not. Is that something not supported, or I am doing something wrong.
Thanks for your help.
Regards
AnarchistGeek
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法看到您的答案是如何解决问题的,直到我意识到我缺少的是有时该属性可以为空,但您得到的不是空引用错误,而是错误列“Address.City”不存在.除非您在格式属性中检查 null ....我在这里找到了答案
I could not see how your answer was fixing the issue until I realised that what I was missing is that sometimes the property can be null but instead of a null reference error you get the error Column "Address.City" does not exist. unless you check for null in the format property....I found the the answer here
这是我在 ASP.NET 论坛中得到的答案,我想将其发布在这里,以防其他人可能需要。
线程链接是 http://forums.asp.net/p/1718114/4586676.aspx/1?Re%20Complex%20data%20type%20in%20WebGrid
解决方案是(经过测试):
我希望它对其他人有帮助。
干杯。
This is the answer I got in ASP.NET forums and I wanted post it here in case others may need that.
The thread link is http://forums.asp.net/p/1718114/4586676.aspx/1?Re%20Complex%20data%20type%20in%20WebGrid
and the solution is(Tested):
I hope it helps others.
Cheers.