Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Razor formatting with a model that is a collection

I have a display template in MVC that is for a collection of items, so the first line of my cshtml file is as follows:

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

If I add some new HTML to the file and then do CTRL + K + D to auto format, it now changes my model to all lower case like this:

@model IList<some.namespace.viewmodels.mylistitem>

This is a massive pain to keep changing after auto formatting, because it obviously breaks my html helpers until I correct the casing. I found this question and it said it was due to MVC3.

I'm running VS2013 Update 4 with MVC5 and I still have this problem. I can't find anything in the Text Editor options to change this behaviour.

I'm also using ReSharper 8.2 and Web Essentials 2013 for Update 4.

Is this a known issue or do I have a setting that is breaking things somewhere?

like image 502
Alex Avatar asked Apr 07 '15 01:04

Alex


1 Answers

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

In the web.config of Views folder overwrite MvcWebRazorHostFactory with this line

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

Close Any open cshtml files and open them.Now formatting the document should work fine, Also I had intellisense problem in razor page which was also resolved. I tried both and did not have any problem.

If you still encounter problems let me know.

like image 155
Rajshekar Reddy Avatar answered Oct 14 '22 00:10

Rajshekar Reddy