Reputation: 12341
When I try to format code of cshtml document with visual studio, a lot of carriage returns are deleted.
As example, this code:
<div class="float-left">
@Html.LabelFor(model => model.StartDate)
</div>
<div class="float-left" style="margin-left: 10px; margin-top: 5px; margin-right: 30px;">
@Html.EditorFor(model => model.StartDate)
</div>
Is changed to this when I do the format command of visual studio:
<div class="float-left">
@Html.LabelFor(model => model.StartDate)
</div>
<div class="float-left" style="margin-left: 10px; margin-top: 5px; margin-right: 30px;">
@Html.EditorFor(model => model.StartDate)
</div>
Note that there is no more empty line between the two divs.
Is it possible to prevent visual studio removing the carriage returns?
Thank you.
Upvotes: 1
Views: 1041
Reputation: 4112
Under Tools > Options > Text Editor > HTML > Formatting
, there is a button labeled Tag Specific Options...
Here you will find many options for HTML tags and ASP.NET Controls. Since Razor is just HTML with some extra syntax sugar, the HTML settings should govern the formatting.
For example, under Client HTML Tags
, if you set div
to have 2 Before opening, within, and 2 after closing
for Line Breaks
, I think this will give you what you are looking for.
Upvotes: 1