Formatting Visual Studio Razor Using a Collection Model

I have a display template in MVC that is for a collection of elements, so the first line of my cshtml file looks like this:

 @model IList<Some.Namespace.ViewModels.MyListItem> 

If I add new HTML to the file and then do CTRL + K + D to automatically format it, it will now change my model to all of the following lines:

 @model IList<Some.Namespace.ViewModels.MyListItem> 

This is a huge pain that continues to change after automatic formatting, because it clearly breaks my html helpers until I fix the case. I found this question , and he said that it is related to MVC3.

I am running VS2013 Update 4 with MVC5 and I still have this problem. I cannot find anything in the text editor settings to change this behavior.

I also use ReSharper 8.2 and Web Essentials 2013 for update 4.

Is this a known issue or do I have a parameter that is breaking something?

+6
source share
1 answer

This is what you need to do to fix the formatting problem.

In the web.config Views folder, MvcWebRazorHostFactory with this line

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Close all open cshtml files and open them. Now formatting the document should work fine. There was also a problem with intellisense on the razor page, which was also resolved. I tried both and had no problems.

If you are still having problems, let me know.

+3
source

Source: https://habr.com/ru/post/984766/


All Articles