在asp.net mvc中动态设置displayname数据注释
我有一个包含以下字段
item_key 的数据库表, 项目值, 显示名称, uihint
我希望能够在数据库表中指定要使用的显示模板以及显示名称。
<%= Html.EditorFor(p=>pageField.item_value, pageField.uihint) %>
UIHint 正在工作,但我无法找到动态设置显示名称的方法,上面的代码生成类似的内容
item_value 文本框
item_value 文本框
item_value 文本框
我希望从 display_name 字段中提取 item_values 标题。
是否可以通过数据注释来做到这一点?一直在查看 http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute%28v=VS.95%29.aspx 并四处搜索,但没有找到任何我所追求的例子
I have a database table with the following fields
item_key,
item_value,
display_name,
uihint
I want to be able to specify in the database table which displaytemplate to use and also the displayname.
<%= Html.EditorFor(p=>pageField.item_value, pageField.uihint) %>
The UIHint is working, but I can't work out a way of setting the displayname dynamically, the above code is producing something like
item_value TEXTBOX
item_value TEXTBOX
item_value TEXTBOX
Where I want the item_values titles to be being pulled from the display_name field.
Is it possible to do this with data annotations? Have been looking at the http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute%28v=VS.95%29.aspx and searching around, but haven't managed to find any examples of what I am after
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须实现您的自定义 ModelMetaDataProvider 才能做到这一点。此链接应该可以帮助您开始:
http ://dotnetslackers.com/articles/aspnet/Customizing-ASP-NET-MVC-2-Metadata-and-Validation.aspx
You have to implement your cusotm ModelMetaDataProvider to do that. This link should get you started:
http://dotnetslackers.com/articles/aspnet/Customizing-ASP-NET-MVC-2-Metadata-and-Validation.aspx