ASP.net MVC - rendering a List containing different types, with a different view for each type

后端 未结 5 1055
清歌不尽
清歌不尽 2020-12-29 00:29

Imagine I have a list of objects that implement an interface called ISummary The objects within this list MAY have additional properties ie.

public interface         


        
5条回答
  •  抹茶落季
    2020-12-29 00:48

    Lewis is on the right track. I would take a slightly different tack--have both of the "widgets" extend from a common base class which provided information about the view names involved. Then add an extension method to your page class to "render widget" which could get the appropriate view in place.

    Check out the Kona ASP.NET MVC sample app for a working example of this concept.

提交回复
热议问题