Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor Helper Syntax Auto Formatting Ugly. How to fix?

So I just have a beef with the way Visual Studio formats razor code. I've always had some problems with visual studio and how it formats UI code, it always seems to do a real super bad job that the industry doesn't want to follow.

So the example looks real real stupid. And I'm trying to figure out if there are mods or ways to fix this issue. It just looks real real bad.

Anyone know anything about this? lol

@using Company.Mobile2.Enums @helper BidsByShipment(string generatedId, int bidsCount, int activeBidsCount)     {         if (bidsCount > 0)         {     <a class="Company-listview-link Company-listview-bids" href="/Shipping/Bids/ByShipment?id={0}">         @if (activeBidsCount > 0)         {             <text>@bidsCount (@activeBidsCount @GetStr("Company"))</text>         }         else         {             <text>@bidsCount</text>         }     </a>         }         else         {     <text>0 @GetStr("Company")</text>         } } 
like image 907
BradLaney Avatar asked Jun 23 '11 19:06

BradLaney


People also ask

How do I stop Visual Studio from auto formatting?

The solution was to go to 'Tools > Options > Text Editor > Basic > VB Specific' and turn 'Pretty Listing' OFF.

How do I Auto beautify code in Visual Studio?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.


2 Answers

Apparently there's no way around it for the moment, this is what they have answered in another related question: Why doesn't Visual Studio code formatting work properly for Razor markup?

like image 130
Alpha Avatar answered Oct 03 '22 01:10

Alpha


Do you have Visual Studio set up to use tab indentation? This reveals a Razor formatting bug where it inserts spaces instead of tabs as it should. The workaround is to switch to space indentation.

like image 37
Josh Mouch Avatar answered Oct 03 '22 02:10

Josh Mouch