ASPX .Master 页面是否可以使用 Razor 视图? [英] Is Razor view with ASPX .Master page possible?

查看:29
本文介绍了ASPX .Master 页面是否可以使用 Razor 视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以保留我现有的 .master 页面并将其与新的 ASP.NET MVC 3 Razor 视图一起使用?我试过这个:

Is it possible to keep my existing .master page and have it used with a new ASP.NET MVC 3 Razor view? I tried this:

@{
   LayoutPage = "~/Views/Shared/Site.master";
 }

它给了我这个错误信息:

And it gives me this error message:

无法呈现文件~/Views/Shared/Site.master",因为它不存在或不是有效页面.

The file '~/Views/Shared/Site.master' could not be rendered, because it does not exist or is not a valid page.

推荐答案

很遗憾没有.母版页是 ASPX WebForms 视图引擎的一部分,而不是 MVC 框架,因此 Razor 无法与其互操作.

Unfortunately no. Master pages are a part of the ASPX WebForms view engine, not the MVC framework so Razor cannot interoperate with it.

一种选择是复制母版,正如您所提到的,但不是复制所有代码,您可以将母版页分解为 Razor 和 ASPX 母版可以嵌入的一堆 ASPX 部分.然后,您可以开始将每个页面和部分页面一一转换为 Razor,最终摆脱 ASPX 母版.

One option would be to duplicate the masters, as you mentioned, but rather than copying all the code, you could factor the Master page into a bunch of ASPX partials that the Razor and ASPX masters could embed. Then you can start converting each page and partial, one-by-one, to Razor and eventually get rid of the ASPX master.

这篇关于ASPX .Master 页面是否可以使用 Razor 视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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