views:

20

answers:

1

I have a model class that is a generic type. I would like to create a custom editor template that would display it (and put it in the Shared folder).

How can I do that?

I can't figure out how to name it so that MVC2 would pick it up over the generic template.

Additionally I am wondering if there is a way to explicitly specify which template a top-level class should use (like you can do with a property using UIHint attribute). Is there a way to override the functionality that picks the templates based on the class name?

Please help.

A: 

The easiest way is to accomplish #1 is to specify the template name when displaying the model, as the second parameter:

<%= Html.DisplayFor(m => m.GenericList, "DisplayList")%>

The handling is generics isn't very good in MVC2. The source code says:

// TODO: Make better string names for generic types

So, when rendering a list, it look for a template named List`1 be default to render it, if you don't specify another name.

On the second point, you would would do the same as #1. Specify the templatename or use UIHint when rendering the item.

RichardAZ