2

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:

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

Mat
  • 202,337
  • 40
  • 393
  • 406
bendr
  • 2,415
  • 6
  • 19
  • 24

2 Answers2

4
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.

Mike Brind
  • 28,238
  • 6
  • 56
  • 88
1

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

Haroon
  • 1,052
  • 13
  • 28