C# 中使用 Razor 的多行语句
我尝试使用 Razor 语法编写一条语句,该语法使用 mvccontrib 网格,其中 流畅的界面在很长的一行中做出了声明。我想将它分散在多行中,如下所示:
@Html.Grid(Model).Columns(column =>
{
column.For(x => Html.ActionQueryLink(x.Name, "Edit", new { id = x.Id })).Named("Name");
column.For(x => x.Number).Named("Number");
}
).Attributes(@class => "grid-style"
).Empty("No data.")
是否可以将最后两行开头的括号放在每行前一行的末尾?
当我尝试将括号放在每行末尾并尝试用点开始编写新行时,该新行会被解释为原始输出的文本。
我觉得奇怪的是新行以括号开头。
I try to write a statement with Razor syntax that use mvccontrib grid where a fluent interface makes statement in a long line. I want to scatter it in multiples lines like this:
@Html.Grid(Model).Columns(column =>
{
column.For(x => Html.ActionQueryLink(x.Name, "Edit", new { id = x.Id })).Named("Name");
column.For(x => x.Number).Named("Number");
}
).Attributes(@class => "grid-style"
).Empty("No data.")
Is it possible to put the parentheses that are at the beginning of the last two lines at the end of previous lines of each?
When I try to put the parentheses at the end of each line and try to start writing new line with a dot, this new line is interpreted like a text to raw output.
I find it odd that the new lines start with a parenthesis.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需在代码块的开头添加一个左括号即可。将代码更改为:
另一方面,在流畅的界面中用点开始新行通常被认为是更好的代码风格,而不是上一行的右括号。正如本例所示。
You just need to add an open parenthesis at the beginning of the code nugget. Change your code to:
On an aside, it's generally considered better code style to begin new lines in a fluent interface with the dot, rather than the closing parentheses from the previous line. As in this example.