Razor Helper 语法自动格式化丑陋。如何修复?
所以我只是对 Visual Studio 格式化 razor 代码的方式感到不满。我一直对 Visual Studio 以及它如何格式化 UI 代码有一些问题,它似乎总是做得非常糟糕,业界不想效仿。
所以这个例子看起来真的很愚蠢。我正在尝试找出是否有模组或方法可以解决这个问题。它看起来真的很糟糕。
有人知道这件事吗?哈哈
@using Company.Mobile2.Enums
@helper BidsByShipment(string generatedId, int bidsCount, int activeBidsCount)
{
if (bidsCount > 0)
{
<a class="Company-listview-link Company-listview-bids" href="/Shipping/Bids/ByShipment?id={0}">
@if (activeBidsCount > 0)
{
<text>@bidsCount (@activeBidsCount @GetStr("Company"))</text>
}
else
{
<text>@bidsCount</text>
}
</a>
}
else
{
<text>0 @GetStr("Company")</text>
}
}
So I just have a beef with the way Visual Studio formats razor code. I've always had some problems with visual studio and how it formats UI code, it always seems to do a real super bad job that the industry doesn't want to follow.
So the example looks real real stupid. And I'm trying to figure out if there are mods or ways to fix this issue. It just looks real real bad.
Anyone know anything about this? lol
@using Company.Mobile2.Enums
@helper BidsByShipment(string generatedId, int bidsCount, int activeBidsCount)
{
if (bidsCount > 0)
{
<a class="Company-listview-link Company-listview-bids" href="/Shipping/Bids/ByShipment?id={0}">
@if (activeBidsCount > 0)
{
<text>@bidsCount (@activeBidsCount @GetStr("Company"))</text>
}
else
{
<text>@bidsCount</text>
}
</a>
}
else
{
<text>0 @GetStr("Company")</text>
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
显然目前没有办法解决这个问题,这是他们在另一个相关问题中回答的内容: 为什么 Visual Studio 代码格式不能正常用于 Razor 标记?
Apparently there's no way around it for the moment, this is what they have answered in another related question: Why doesn't Visual Studio code formatting work properly for Razor markup?
您是否已将 Visual Studio 设置为使用制表符缩进?这揭示了 Razor 格式化错误,它插入空格而不是应有的制表符。解决方法是切换到空格缩进。
Do you have Visual Studio set up to use tab indentation? This reveals a Razor formatting bug where it inserts spaces instead of tabs as it should. The workaround is to switch to space indentation.
C# 代码的格式与 HTML 代码分开。如果你想要正确的缩进,那么只需在你期望缩进的地方放置一些无用的包装标签,你就会得到缩进。但这将是一种反模式。
这是代码。对于像您定义的函数,我不确定它是否真的有效。
The C# code formats separately from the HTML code. If you want the proper indentation then just put some useless wrapper tags wherever you expect there to be indentation and you'll get the indentation. This would be an anti-pattern though.
Here is code. For a function like you've defined I"m not sure if that actually works.
我制作了一个用于格式化 razor 文档的扩展。
安装:
1) 在扩展中搜索“razor-formatter”
2) 按 CTRL + P,然后输入下面的命令并按 Enter:
VSCode 市场上的链接:
https://marketplace.visualstudio.com/items?itemName=Kookweb.razor-formatter
github 上的源代码:
https://github.com/Kookweb-ir/razor-formatter
当然这不是最好的格式化程序,但这只是目前的格式化程序。
这只是一个简单的 HTML 美化器,适用于 razor 文档。如果有人致力于它并使其完美,我会很高兴。
i make an extension for formatting razor document.
Install:
1) in extensions search for "razor-formatter"
2) press CTRL + P AND then enter command below and press enter:
Link on VSCode marketplace:
https://marketplace.visualstudio.com/items?itemName=Kookweb.razor-formatter
source on github:
https://github.com/Kookweb-ir/razor-formatter
Of course this isn't best formatter, but this is only formatter for now.
this is just a simple HTML beautifier that works on razor documents. i will be happy if anybody works on it and make it perfect.
对于所有抱怨 Visual Studio 的人来说,我认为令人印象深刻的是,它允许您在 HTML 和 C# 之间切换,而无需被告知您正在使用哪种语言。
从更实际的角度来看,我认为我的建议是将上面显示的许多内容结合起来。具体来说...
鉴于这两个,我发现 CTRL K、D 重新格式化代码为表块提供了完美的结果,这让我发疯:
完美的!感谢上述所有 StackOverflow 贡献者。
For all the people whingeing about Visual Studio, I think it's pretty impressive that it allows you to switch between HTML and C# without being told which language you're using.
On a more practical note, I think my advice would be to combine lots of the things shown above. Specifically ...
Given these two I've found that CTRL K, D to reformat code gave perfect results for a table block which has been driving me mad:
Perfect! Thanks to all StackOverflow contributors above.