Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 cshtml file errors

I opened my existing VS2015 solution in the new VS2017. Was hoping it would just work, however, I am seeing a lot of red lines under words like - @model, @ViewBag, @ActionLink, @Url, @Partial, @Scripts, @Styles, and under lambda expressions in the where clause on the model for the page.

Not sure what is missing or wrong. The solution builds, but shows errors in the cshtml files.

Anyone help or direction would be helpful.

Thanks in advance. Ken

like image 972
Ken Cronin Avatar asked Mar 09 '17 21:03

Ken Cronin


People also ask

What file type is Cshtml?

What is a CSHTML file? A file with . cshtml extension is a C# HTML file that is used at server side by Razor Markup engine to render the webpage files to user's browser.

Is Cshtml and HTML same?

Cshtml is basically razor view extension and any view renders in html finally. You need to use Razor in your application as it supports server side code but raw html does not.

What is the difference between Cshtml and ASPX?

One major advantage to aspx compared to cshtml is that you can view and edit the page itself (WUSIWYG kind of) using the design tab. With cshtml files you might as well use notepad to edit your html page. You are working "in the dark".


1 Answers

I had this issue and https://stackoverflow.com/a/19696998/4484478 fixed it for me. My solution was created with VS2012. I started using VS2013 and VS2015 to work on this solution after RTM came out and the issue OP described occurred after I started using VS2017.

From the answer post:

Create a new project targeting same .NET framework and copy its Views/web.config file over top the one in your current project.

Note that the web.config here is the one inside the Views folder and not the main one. This is probably the simplest way to fix it. But if you have some other customization in this file you can try editing manually the version numbers for Razor and MVC. Mine changed from 2.0.0.0 -> 3.0.0.0 for Razor

enter image description here

And 4.0.0.0 -> 5.2.3.0 for MVC enter image description here

enter image description here

like image 136
noriMonsta Avatar answered Oct 23 '22 04:10

noriMonsta