I have a WebGrid
that I am trying to define in an MVC4 razor view. I would like to define a column format using multiple lines for readability. The following works, with the format on one line:
@grid.GetHtml(
columns: grid.Columns(
grid.Column(
header: "Address",
format: (item) => @: @item.Address.Street1 @item.Address.Street2<br />@item.Address.City, @item.Address.State @item.Address.Zip
)
)
)
The following gives a parser error, ; expected
, on the first trailing parenthesis, and Invalid expression term ')'
on the other trailing parentheses:
@grid.GetHtml(
columns: grid.Columns(
grid.Column(
header: "Address",
format: (item) => @: @item.Address.Street1 @item.Address.Street2<br />
@: @item.Address.City, @item.Address.State @item.Address.Zip
)
)
)
After reading ScottGu's blog, I thought this was the proper multiline syntax. I have tried various placements of curly braces, semicolons, and parentheses, and I can't find a syntax that makes the parser happy.
After toying with it for a little while longer I was able to find a working version using the <text>
tag.
@grid.GetHtml(
columns: grid.Columns(
grid.Column(
header: "Address",
format: @<text>@item.Address.Street1 @item.Address.Street2<br />
@item.Address.City, @item.Address.State @item.Address.Zip</text>
)))