setting displayname data annotation dynamically in asp.net mvc

心不动则不痛 提交于 2019-12-11 23:17:32

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/3228378/setting-displayname-data-annotation-dynamically-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!