如何获得局部视图使用的布局?

时间:2019-04-02 14:20:39

标签: c# asp.net razor

我的项目中有几个布局(母版页),我想根据共享的部分页面所使用的布局来做一些条件。有没有办法获取这些部分使用的布局页面?

到目前为止,我已经尝试过:

@{
  if (Layout == "_MasterPage") //layout always come as NULL, even thought it is being used correctly
}

还有其他方法可以检查所使用的布局吗?

1 个答案:

答案 0 :(得分:0)

"Is there any other way to check for the Layout used?"

Yes, there is. You can use a specific model (and use regular OOP inheritance) and check in your partial, for instance.

Also, it feels like a hack, but nothing is stopping you from defining a cookie or something when using one master page or the other and checking that inside your partial.