开发者

Inserting Hyperlinks into the WebGrid

I have searched high and low, and it was only a few weeks ago I saw heaps of sites that had little samples for this, but for the life of me can't find them now!

I have a webgrid, and for certain columns, I need to insert hyperlinks into the rows, like:

&l开发者_如何转开发t;a href="someurl.cshtml?something=this&that=something" title="eh?">@rowValue</a>

Are there any Docs for this? All I can seem to find on MSDN is very basic stuff, and this doesn't seem to be in there.

Thanks!


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

The format parameter will accept HTML, so long as you prefix it with the @ sign and it is self-closing, or wrapped in <text> tags. It's a Razor Template, which is described by Phil Haack here and Andrew Nurse here.


Alternatively you can use the format with @Html.ActionLink, e.g.

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>)

In the code fragment "item" has property "Customer" that has properties LastName and FirstName

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜