开发者

Can the MasterPage be designated from the Controller?

I have a couple different userTypes (Admin, User) and a MasterPage for each. I am beginning t开发者_开发百科o create some Views that will be used by both userTypes where i would like to assign the MasterPage programmaticly (based on _currentUser).

Possible?

thx


Use Controller.View() overload

return View("MyView", "MyMaster");

in your controller to determine the view and the master page it should use.

public ViewResult Index() {
  if (User.IsInRole("Admin")) {
    return View("Index", "AdminMaster");
  }
  else {
    return View("Index", "DefaultMaster");
  }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜