Indentation is broken in Visual Studio .cshtml files

后端 未结 3 405
北恋
北恋 2021-01-17 12:12

It\'s the most infuriating thing and after 45 minutes of Googling and testing I caved to the forum gods... I simply cannot live without automatic indentation, even if it\'s

相关标签:
3条回答
  • 2021-01-17 12:48

    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.

    0 讨论(0)
  • 2021-01-17 12:56

    I work with VS2017 (asp.net core 2.2), use Devextreme controls and have exactly the same problems.
    I have deactivated the automatic auto format after copy paste since a longer time now (as it don't work).
    As I have large views with > 100 DE controls (each with about 5 properties in average), I have to format the view (with "Format document" whereby "Format selection" don't work in my installation, b.t.w.) from time to time, to make the file structure "readable".

    If I do so, I have exactly the same problem (the lines are intended to the right until they are not visible as "out of monitor" and I have a large monitor...).
    To make the file "readable" again, I have to edit every single line manually (remove wrong space).

    I have wasted hours now with try-and error. The only (very ugly and bad) "workaround" I found is, to write the whole code on ONE line.
    Example: @(Html.DevExtreme().TextBox().ID("AngebotFirma").Value(@Model.PAB_Firma).MaxLength(45).Placeholder("Firma...").InputAttr("autocomplete", "company") )

    This way, the whole document (HTML, JQuery and also Devextreme (the one line) is formatted (intended) correct.

    So.. this is not a solution, but may be a workaround to save time. I change my code to "one line code" at least until I have finished and tested the views. After that, I - maybe - will change the code back to "multiline"...

    0 讨论(0)
  • 2021-01-17 12:57

    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.

    0 讨论(0)
提交回复
热议问题