I'm having issues creating an ActionLink using Preview 5. All the docs I can find describe the older generic version.
I'm constructing links on a list of jobs on the page /jobs. Each job has a guid, and I'd like to construct a link to /jobs/details/{guid} so I can show details about the job. My jobs controller has an Index controller and a Details controller. The Details controller takes a guid. I've tried this
<%= Html.ActionLink(job.Name, "Details", job.JobId); %>
However, that gives me the url "/jobs/details". What am I missing here?
Solved, with your help.
Route (added before the catch-all route):
routes.Add(new Route("Jobs/Details/{id}", new MvcRouteHandler())
{
Defaults = new RouteValueDictionary(new
{
controller = "Jobs",
action = "Details",
id = new Guid()
})
});
Action link:
<%= Html.ActionLink(job.Name, "Details", new { id = job.JobId }) %>
Results in the html anchor:
http://localhost:3570/WebsiteAdministration/Details?id=2db8cee5-3c56-4861-aae9-a34546ee2113
So, its confusing routes. I moved my jobs route definition before the website admin and it works now. Obviously, my route definitions SUCK. I need to read more examples.
A side note, my links weren't showing, and quickwatches weren't working (can't quickwatch an expression with an anonymous type), which made it much harder to figure out what was going on here. It turned out the action links weren't showing because of a very minor typo:
<% Html.ActionLink(job.Name, "Details", new { id = job.JobId })%>
That's gonna get me again.