Indentation is broken in Visual Studio .cshtml files

Since 3 weeks (since Update to Visual Studio 2015 SP 2 after VS 2013) I had the problem, that copy/paste and comment in cshtml files destroy my format of my file. Interestingly the tab indent was at column 7. I don't understand why.

After Update to VS 2015 SP 3, the problem was not banned.

Then I found out, that in my cshtml files a "@" sign destroyed my copy/paste/comments:

@model MAWGridModel<AktionGridRowModel>

@if (Model != null)
{
    @Html.DevExpress().GridView(settings =>
    {
        settings.Name = "MAWAktionenErgebnisGrid";
    ...
    }).Bind(Model).GetHtml();
}

The "@"before "Html.DevEpress()..." destroyed all. Here the code snippet which works for me. (I hope it will really do.)

@model MAWGridModel<AktionGridRowModel>

@if (Model != null)
{
    Html.DevExpress().GridView(settings =>
    {
        settings.Name = "MAWAktionenErgebnisGrid";
        // ...
    }).Bind(Model).Render();
}

Hopefully it helps you.


You mentioned that you just installed Resharper before this problem started occurring, so your problem is most likely being caused by Resharper.

By default Resharper does many extra formatting fixes as you type, but you'll likely find a bunch of these default fixes conflict with your coding style.

You can configure Resharper's code formatting options via Resharper > Options > Code Editing > HTML|Razor|etc > Formatting Style

In this case, your problem was the setting Do not indent children of contained tags that you didn't want by default.