Why doesn't Visual Studio code formatting work properly for Razor markup?

后端 未结 10 1631
醉梦人生
醉梦人生 2020-12-08 13:04

Or, should I rather ask, when will VS code formatting work properly for Razor markup? The formatting works for most structures, but it seems to choke on \'if\' blocks. The c

10条回答
  •  悲&欢浪女
    2020-12-08 13:18

    I know it's not really the answer you're looking for but I've used WriteLiteral to get around my formatting issues.

    For example, when I write:

    @foreach (var item in Model) { if (condition) { @:

    Visual Studio tries to change it to:

    @foreach (var item in Model) { if (condition) { @:

    Which causes the page to throw an error.

    If you use WriteLiteral you can fool the formatter into ignoring the line but it ain't pretty:

    @foreach (var item in Model) { if (condition) { WriteLiteral("
    "); } @item.Label }

提交回复
热议问题