Consider this code:
<%: Html.DisplayFor(model => model.SomeBoolean)%>
<%: Html.DisplayFor(model => model.SomeInt)%>
First one is bound to a boolean this will re开发者_运维百科nder a disabled drop down list. The second is bound to an int and this will simply render the result as text.
I would like the int to also render a drop down list too.
What are my options?
Many thanks.
MVC has a set of default editor and display templates. You can create your own by creating a DisplayTemplates folder in either the view folder for the controller, or you can define a more global template by putting it in a DisplayTemplates folder in the Shared folder.
For system types, use the actual type name and not the language specific shortcut (i.e. for int
, call the template Int32.ascx
or Int32.cshtml
for Razor.
You can further specify templates by either using an overload (I know this is possible for EditorFor, I'm guessing it is for DisplayFor as well), or if you have a specific property that you want to use a different template for, you can use data annotations.
This same technique works for complex types as well.
精彩评论