开发者

Extending MVC TemplateHelper / DisplayFor* methods - should I be doing that?

So in MVC3 beta, I'm looking for a controllable way to use a different set of display templates than those I've put in the DisplayTemplates folder.

Probably easiest to just say exactly wha开发者_JAVA百科t I'm trying to do, using stackoverflow as an example:

On the details page, you can imagine that you would have:

Html.DisplayForModel() // Uses the DisplayTemplates/question.ascx

Now on the listing page showing all the questions I want:

Html.SummaryForModel() // Uses the SummaryTemplates/question.ascx

The reason for this is I want an easy way to display various objects all in one list without having to specify in the page the actual template to use (using RenderPartial or whatever).

So looking at the implementation of DisplayForModel(), this should be a simple task - but TemplateHelper is all internal so am I missing some other hook I could be overriding, or do I have to implement my own version of this?


I've done a similar thing with an auto-grid and yes you have to create your own helpers that loops through your models properties and then does the call to with the appropriate RenderPartial("/yourfilepaths").

The issue you'll run into is that those internal classes shuffle around the metadata about the object for you, reads the UIHint attributes and all of that jazz. Implementing your own isn't hard but takes some work to get the implementation right.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜