Visual Studio 2012 code formatting on the bottom lines of CSHTML generates typical model types

When formatting the code of a Razor cshtml file in Visual Studio 2012 (with Ctrl + K + D), if the model is a generic type, VS makes everything lowercase. For example:

@model IEnumerable<Content> 

converted to (takes into account all the contents of the lower case):

 @model IEnumerable<Content> 

after formatting. This causes the code to not compile. Is this a mistake, or am I missing something? How can this be fixed?

+8
code-formatting visual-studio-2012 razor
source share
3 answers

This issue is related to Visual Studio 2012, which does not recognize it as razor code and treats it like plain HTML. I believe that this is a mistake with VS 2012 and hopefully it will be fixed soon. As a temporary fix, you can do this:

  • Go to TOOLS → OPTIONS
  • Choose a text editor → HTML → Formatting
  • Set the customer tag to "As indicated"

Hope this helps.

+11
source share

If this is a new project in VS 2012, you need to add this line of code to your <appSettings> section of the main web.config :

 <add key="webpages:Version" value="1.0.0.0"/> 

If it was an existing project, you probably already have this key in web.config . Make sure it is for version 1.0.0.0 , not 2.X or 1.2.X

Also make sure that the link to the System.Web.WebPages project matches version 1.0.0.0 and not 2.0.0.0

After making these changes, you need to close and reopen Visual Studio 2012!

+2
source share

The following worked for me with Visual Studio Professional 2012, ASP.NET MVC 5, and Microsoft.System.Web.WebPages 3.0 :

 <add key="webpages:Version" value="3.0.0.0" /> 

But this solution did not work right away

First, Chris Haddox’s decision regarding webpages:Version :

 <add key="webpages:Version" value="1.0.0.0"/> 

did not work for me, I already had this key, and it was set to 1.0.0.0.

But since I am using Visual Studio Professional 2012, ASP.NET MVC 5 and Microsoft.System.Web.WebPages 3.0 ...

This problem showed that my Web.Config webpages:Version was set to 1.0.0.0 , I changed it to 3.0.0.0 because I read in another article, which may be correct for Microsoft.System.Web.WebPages 3.0 and I’m all there was still a formatting error for a while.

I continued to make changes to my .cshtml file. Then all of the sudden formatting started working correctly. Maybe from a building, but I don’t think I did the assembly, but I can’t be sure, and I know that I did not restart Visual Studio 2012.

0
source share

All Articles