指定不同的_Layout.cshtml取决于控制器 [英] Specify different _Layout.cshtml depending on controller

查看:293
本文介绍了指定不同的_Layout.cshtml取决于控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个ASP MVC3项目,我想有一个不同的_Layout.cshtml取决于所选择控制器。这是因为,与控制器1具有2个按钮与控制器2将有3并与controller3会有4.每个控制器是用于用户的特定类型,所以它依赖于登录

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.

如何链接控制器和意见,另一个Layout.cshtml,现在有一个布局,它的共享文件夹下。

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.

谢谢!

推荐答案

视图应确定的布局,而不是控制。

The View should determine the layout, not the controller.

该控制器应该只是确定什么视图返回。

The Controller should just determine what View is returned.

然后在您的视图的顶部,你可以指定布局。 你可以添加一个if语句围绕它去改变它根据你的数据。

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

@{
    if(ViewBag.someValue)
       Layout = "~/Views/Shared/_Layout.cshtml";
    else
        Layout = "~/Views/Shared/_otherLayout.cshtml";
}

这篇关于指定不同的_Layout.cshtml取决于控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆