2011-06-26 58 views
2

我已經搜索了高和低,並且僅僅幾個星期前,我看到了堆積如山的網站,但是對於我而言,現在終身無法找到它們!在WebGrid中插入超鏈接

我有一個的WebGrid,對於某些列,我需要插入超鏈接入行,如:

<a href="someurl.cshtml?something=this&that=something" title="eh?">@rowValue</a> 

是否有任何文檔的呢?我在MSDN上看到的所有東西都是非常基本的東西,而這似乎並不在其中。

謝謝!

回答

4
grid.Column(
    format: @<a href="someurl.cshtml?something=this&that=something" title="eh?">@row.Value</a> 
) 

format參數將接受HTML,只要你與@符號前綴它,它是自閉,或包裹在<text>標籤。這是一個剃刀模板,由Phil Haack hereAndrew Nurse here描述。

+0

謝謝很多@Mike,大加讚賞。 – bendr

1

或者,您可以使用帶@ Html.ActionLink的格式,例如

grid.Column( header: "Name", canSort: true, columnName: "Customer.LastName", format: @<text>@Html.ActionLink(linkText: (string)@item.Customer.LastName + ", " + (string)@item.Customer.FirstName, actionName: "Details", routeValues: new { id = item.Id }) </text>)

在代碼片段「項目」具有屬性「客戶」有性質姓氏和名字