I have an action method returning a JsonResult
in my controller:
public JsonResult GetDetails()
{
var rows = //Linq-To-SQL
//Linq-To-Entities
var lifts = (from r in rows
group r by new { r.LiftID, r.LiftDate } into g
select new
{
ID = g.Key.LiftID,
Date = g.Key.LiftDate.ToShortDateString(),
Driver = g.Where(x => x.IsDriver)
.Select(x => x.p).Single().Name,
Passengers = g.Where(x => !x.IsDriver)
.Select(x => x.p.Name)
.Aggregate((x, y) => x + ", " + y)
}).ToList();
return Json(lifts);
}
I use the result in a jQuery script to write out a table.
The data looks like:
ID | Date | Driver | Passengers
1 | 20/06/2010 | David Neale | John Smith, Paul Jones
etc...
I would like the names to be hyperlinks to the route Person\{id}
I.e. <a href="\Person\7">David Neale</a>
. The p
property corresponds to a Person
object containing both Name
and ID
.
I don't want to construct the URL manually. How would I construct the object to contain the names as hyperlinks using the MVC routing engine?