简体   繁体   English

ASP.NET MVC在现有项目中更改视图引擎 - 从Razor到ASPX

[英]ASP.NET MVC Change View Engine in existing project - From Razor to ASPX

There are few posts about changing ASP .NET view engine from ASPX to Razor. 关于将ASP .NET视图引擎从ASPX更改为Razor的帖子很少。 However, I have a business need where I need to change my view engine from Razor to ASPX because we are using enterprise frameworks controls that only render pages in ASPX view engine. 但是,我有一个业务需求,我需要将我的视图引擎从Razor更改为ASPX,因为我们使用的企业框架控件只在ASPX视图引擎中呈现页面。 How do I do this? 我该怎么做呢?

I understand that it's trivial when we are setting up the project but this is an existing project. 我知道在设置项目时这是微不足道的,但这是一个现有的项目。 I have tried the following in Global.asax.cs but its does not have an option to add ASPX view engine, am I missing something here? 我在Global.asax.cs中尝试了以下内容,但它没有添加ASPX视图引擎的选项,我在这里遗漏了什么?

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine()); // no ASPX view engine option? 

Any other way we can change View Engine from Razor to ASPX for an existing project? 我们可以将View Engine从Razor更改为现有项目的ASPX吗? Otherwise, I have to create a new solution using ASPX as view engine and port all the codes, super unproductive. 否则,我必须创建一个新的解决方案,使用ASPX作为视图引擎并移植所有代码,超级无效。

You can add the Web Forms view engine using: 您可以使用以下命令添加Web窗体视图引擎

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new WebFormViewEngine());

You can even have both view engines in a single project if you don't want to rewrite any existing Razor views using the Web Froms engine. 如果您不想使用Web Froms引擎重写任何现有的Razor视图,您甚至可以在一个项目中同时拥有两个视图引擎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM