开发者

BaseViewModel for every Request

Is there a way that I can pass the same BaseViewModel for every request without returning either the BaseViewModel or something that inherits from the BaseViewModel for each view? I'm usi开发者_JS百科ng a shared view (_layout.cshtml).


No, there isn't a way. If your view or layout is strongly typed to a class BaseViewModel you need to return an instance of this class (or a derived class) from each controller action that is rendering this view.

As an alternative to the base view model approach you may checkout the Html.Action helper in order to encapsulate some common view functionality.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜