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.
Under
Tools > Options > Text Editor > HTML > Formatting, there is a button labeledTag 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 setdivto have2 Before opening, within, and 2 after closingforLine Breaks, I think this will give you what you are looking for.