C# 使用WebGrid格式参数

C# 使用WebGrid格式参数,c#,asp.net,razor,format,webgrid,C#,Asp.net,Razor,Format,Webgrid,我没有使用MVC。这是一个C#Asp.Net网页项目。没有视图/模型/控制器。我所有的搜索都只找到了对例如:HTML.ActionLink的引用 我正在尝试使用WebGrid.Column.format参数创建链接。我需要使用查询中的一些数据字段 这项工作: anchorGrid.Column(columnName: "Latitude", header: @Sorter("Latitude", "Latitude", anchorGrid), style: "alignRight nowrap

我没有使用MVC。这是一个C#Asp.Net网页项目。没有视图/模型/控制器。我所有的搜索都只找到了对例如:HTML.ActionLink的引用

我正在尝试使用WebGrid.Column.format参数创建链接。我需要使用查询中的一些数据字段

这项工作:

anchorGrid.Column(columnName: "Latitude", header: @Sorter("Latitude", "Latitude", anchorGrid), style: "alignRight nowrap", format: (item) => Html.Raw(item.Latitude.ToString("F5"))),
再次使用相同的数据字段,我尝试了以下操作:

anchorGrid.Column(header: "Map", format: (item) => Html.Raw("<a href='http://maps.google.com/?q=@(item.Latitude.ToString("F5")),@(item.Longitude.ToString("F5"))'>Map</a>")),

anchorGrid.Column(header: "Map", format: (item) => <text><a href='http://maps.google.com/?q=@(item.Latitude.ToString("F5")),@(item.Longitude.ToString("F5"))'>Map</a></text>),

anchorGrid.Column(header: "Map", format: (item) => Html.Raw("<a href='http://maps.google.com/?q=" + item.Latitude.ToString("F5") + ","+ item.Longitude.ToString("F5") + "'>Map</a>")),
anchorGrid.Column(标题:“Map”,格式:(item)=>Html.Raw(“”),
列(标题:“映射”,格式:(项)=>),
列(标题:“映射”,格式:(项)=>Html.Raw(“”),

还有一些与括号和@符号有关的变体。我做错了什么?

您不需要在format参数中使用
Html.Raw
,因为WebGrid助手无论如何都会吐出Html。您只需要在要输出的HTML前面加上
@
符号:

anchorGrid.Column(header: "Map", format: @<a href="http://maps.google.com/?q=@(item.Latitude.ToString("F5")),@(item.Longitude.ToString("F5"))">Map</a>"),
anchorGrid.Column(标题:“映射”,格式:@),

请提供您的答案的上下文。对不起,我忘了我在哪里:)