Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Razor view in MVC 3 after upgrade from MVC 2 hardcoded?

Tags:

c#

asp.net-mvc

I have a MVC 2 project which I am trying to upgrade to MVC 3 but using tool I got the error that SLN file are invalid even it's fine and work for me.

so I Upgrade them manually, It means

In sln file change the keys and change the config file in views and in main directory and remove the MVC 2 dll and add the MVC 3 dll.

now my project convert to MVC 3 but a little problem I fond that when I am trying to add a views I am unable to find the option, It's only show me aspx in the New Window. I need MVC 3 razor based views & layout.

how I can get razor in the menu (add new View option)

like image 764
Anirudha Gupta Avatar asked May 12 '11 10:05

Anirudha Gupta


People also ask

Does Razor use MVC?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine.

What is the difference between MVC and Razor?

A Razor Page is almost the same as ASP.NET MVC's view component. It has basically the syntax and functionality same as MVC. The basic difference between Razor pages and MVC is that the model and controller code is also added within the Razor Page itself. You do not need to add code separately.

Which namespace is used by MVC for Razor view engine?

The namespace for Razor Engine is System. The Razor file extension is "cshtml" for the C# language. By default, Razor View Engine encodes html tags or scripts before it's being rendered to view that avoids Cross-Site Scripting attacks.


1 Answers

You have to do a bit more with the project file. check out this post, similar problem: ASP.NET MVC3, Enable Razor


to paraphrase:

I fixed this by changing the ProjectTypeGuids element in the .csproj file to the following:

<ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

I can now choose either Razor or ASPX as my view engine.


see if that fixes your issue.

Personally I'd create a new MVC3 project and copy over the controllers and views and work on them as I need to.

Remember though if you create a new razor view you will need to remove your existing aspx or ascx view as there are checked for first before cshtml (razor).

like image 102
Luke Duddridge Avatar answered Oct 23 '22 04:10

Luke Duddridge