开发者

BaseViewModel for every Request

开发者 https://www.devze.com 2023-04-12 15:42 出处:网络
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百科

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

精彩评论

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