如何更改默认的MVC布局页面 [英] How to change default MVC layout page

查看:524
本文介绍了如何更改默认的MVC布局页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一些发展,我需要在MVC到实施的登录表单。
我已经创建了VS2013的MVC项目,该项目工程确定。当创建它,VS已经包括形式和配置使用的登录以及寄存器意见。

I'm doing some development where I need to implemented a login form in MVC. I have already created an MVC project in VS2013 which works OK. When creating it, VS already include the forms and configuration to use the LogIn as well as the register views.

下面的事情是,该视图使用layout.cshtml文件作为母版页。所以,如果我把在 [授权] 属性到一个控制器上运行的网站时发生了什么里面的方法是,它显示了登录页面这是确定。但使用layout.cshtml作为母版页。

the thing here is that that view use the layout.cshtml file as a master page. So, if I put the [Authorize] attribute to a method inside a controller what is happening when running the web site, is that it shows the LogIn page which is OK. But using the layout.cshtml as the master page.

有没有显示在entiry窗口LogIn.cshtml页面,而无需使用layout.cshtml的方式?

Is there a way to displayed the LogIn.cshtml page in the entiry window without using the layout.cshtml?

在web.config中我有:

In the web.config I have:

<authentication mode="Forms">
      <forms loginUrl="Account/Login" timeout="2880" />
    </authentication>

不过,这并不正常工作

But it doesn't work

推荐答案

适用于布局中的 Login.cshtml 正在回升,按照惯例,从 _ViewStart.cshtml

The layout applied to the Login.cshtml is being picked up, by convention, from _ViewStart.cshtml.

@{
   Layout = "~/Views/Shared/_Layout.cshtml";
}

如果你不想使用此再增加一个

If you don't want to use this then add a

@{
    Layout = null;
}

@{
    Layout = "SomeOtherMaster.cshtml";
}

到Login.cshtml页面。

to the Login.cshtml page.

但是通过改变你要改变了所有的脚本和CSS引用所以你需要在你自己添加的布局。您应该检查在 /Views/Shared/_Layout.cshtml 来看看你会被放弃。

However by changing the Layout you're going to change out all the script and css references so you'll need to add in you own. You should check in /Views/Shared/_Layout.cshtml to see what you'll be giving up.

这篇关于如何更改默认的MVC布局页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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