根据控制器指定不同的_Layout.cshtml
我创建了一个 asp mvc3 项目,我想要根据选择的控制器有不同的 _Layout.cshtml 。这是因为控制器 1 有 2 个按钮,控制器 2 有 3 个按钮,控制器 3 有 4 个按钮。每个控制器适用于特定类型的用户,因此取决于登录。
我如何将控制器及其视图链接到另一个 Layout.cshtml,现在有一个布局,它位于 Shared 文件夹下。
谢谢!
I created an asp mvc3 project, I want to have a different _Layout.cshtml depending on which controller is selected. This is because with controller 1 it has 2 buttons with the controller2 there will be 3 and with the controller3 there will be 4. Each controller is for a specific type of user, so it depends on the login.
How can i link a controller and its views to another Layout.cshtml, right now there is one layout and it's under the Shared folder.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
视图应该决定布局,而不是控制器。
控制器应该只确定返回什么视图。
然后,您可以在视图顶部指定布局。
您可以在其周围添加 If 语句以根据您的数据更改它
The View should determine the layout, not the controller.
The Controller should just determine what View is returned.
Then in the top of your view you can specify the layout.
You could add a If statement around it to change it based on your data
此时,由于另一个有点过时并且使用 mvc 5 ,我知道您会遇到一些没有括号的问题。 如果您希望使用视图来执行逻辑,那么这里有一个更完整的答案。
控制器
视图
At this point since the other one is a bit dated and with mvc 5 , I know you will have some issues with not having brackets. If you wish to use the View to be doing logic then here is a more complete answer.
Controller
View