C# 中使用 Razor 的多行语句

发布于 2024-12-13 03:18:24 字数 699 浏览 3 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青芜 2024-12-20 03:18:24

您只需在代码块的开头添加一个左括号即可​​。将代码更改为:

@(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."))

另一方面,在流畅的界面中用点开始新行通常被认为是更好的代码风格,而不是上一行的右括号。正如本例所示。

You just need to add an open parenthesis at the beginning of the code nugget. Change your code to:

@(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."))

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文