Is Razor compulsory in ASP.NET MVC 5? [duplicate]

2019-09-04 05:49发布

This question already has an answer here:

I am new to ASP.Net MVC 5 and I want to know if Razor view engine is compulsory, or can you use ASPX view engine?

I try to create new application but I am not getting option to change the view engine.

2条回答
We Are One
2楼-- · 2019-09-04 06:25

Razor views are not compulsory in ASP.net MVC..in ASP.net MVC there are two view Engine are there:

Razor View Engine:

1.Razor View Engine is an advanced view engine and introduced with MVC3. This is not a language but it is a markup syntax.

2.In Razor View Engine we use Layouts.

3.Razor Engine is a little slow compared to Aspx Engine.

Web Form/Aspx View Engine

1.ASPX View Engine is the default view engine for the ASP.NET MVC that is included with ASP.NET MVC from the beginning.

2.In ASPX View Engine we use masterPages.

查看更多
成全新的幸福
3楼-- · 2019-09-04 06:27

Razor views are not compulsory. You can use aspx views. When creating your project there is a dropdown that allows you to select which view engine you want the template to use, if you are creating a project from a template.

However, this option doesn't make any difference to your project apart from the views that vs creates in the template. For example, change the name of one of your views, eg. Change home.cshtml to bob.cshtml. Run the project and navigate to the page that uses this view. You will get an error page which displays a list of views that the framework has attempted to find in different folders. This is an operation that uses convention and is the default method mvc will use to find views. Anyway, in the list you will see aspx and cshtml files, so you can go ahead and create an aspx view and mvc will pick it up. Note that the order of the list in the error message is the order mvc will look up each view. It will use the first one it comes across.

查看更多
登录 后发表回答