开发者

ViewModel in a masterpage? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

I am using asp.net mvc 3.0 with razor.

I am wondering if I can make a view model for my master page. I have some dyn开发者_JAVA百科amic data in my master page so I am going to probably have to make a "base class" for all my controllers but I rather have strongly typed data then View Data/ View Bag.

So can this be done?


You could have all of your view models inherit from a base view model, which would include all of your common fields.

Alternatively, you could use a Custom Action Filter that would put some object in the view data which your master page would always expect to be there. This action filter could also be used to fill in the common fields in your view model base class.


i would suggest using RenderAction rather than having a base viewmodel from which all your view models will inherit. i guess viewmodel that you want to use in your master page is most probably going to contain navigational data (menu or leftbar etc.). if this is the case, RenderAction places clean separation of concerns and you can cache the data used in this particular action after loading it for first time and your further request will then be served from cached data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜