Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi lines statements with Razor in C#

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.

like image 572
Samuel Avatar asked Nov 01 '11 13:11

Samuel


1 Answers

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.

like image 107
Aaronaught Avatar answered Oct 20 '22 10:10

Aaronaught