ASP.net MVC Areas and creating an ActionLink with ID (SEO / clean URL)?

Up vote 1 down vote favorite share g+ share fb share tw.

I am building a Help Desk Ticket system for a client using ASP. NET MVC 1.0 / C#. I have implemented Steven Sanderson's "App Areas in ASP.

NET MVC, Take 2" and it is working great. In my Globabl. Asax page I have some routes defined as such: public static void RegisterRoutes(RouteCollection routes) { // Routing config for the HelpDesk area routes.

CreateArea("HelpDesk", "ProjectName.Areas.HelpDesk. Controllers", routes. MapRoute(null, "HelpDesk/{controller}/{action}", new { controller = "Ticket", action = "Index" }), routes.

MapRoute(null, "HelpDesk/Ticket/Details/{TicketId}", new { controller = "Ticket", action = "Details", TicketId = "TicketId" }) ); } So, if I enter "http://localhost/HelpDesk/Ticket/Details/12" in the browser address bar manually, I get the results I expect. Here is my controller: public ActionResult Details(int TicketId) { hd_Ticket ticket = ticketRepository. GetTicket(TicketId); if (ticket == null) return View("NotFound"); else return View(ticket); } In my view I have: But that code generates "http://localhost/HelpDesk/Ticket/Details?

TicketId=12" which also returns the expected results. My Question is... How do I define an ActionLink when using Steven Sanderson's Areas that will create a clean URL like: "http://localhost/HelpDesk/Ticket/Details/12"? Asp.

Net-mvc asp. Net-mvc-routing link|improve this question edited Aug 17 '09 at 12:45 asked Aug 14 '09 at 19:48robnardo514313 92% accept rate.

Try The ActionLink method expects a dictionary with keys that match the parameter names. (Note that passing an anonymous object is a convenience for this). Anything else I believe it will just tag onto the end of the URL.

EDIT: The reason that this isn't working for you is because your first route matches and takes precedence (controller and action), but defines no TicketId parameter. You need to switch the order of your routes. You should always put your most specific routes first.

Womp... there it is! You are correct. It was the order!

– robnardo Aug 17 '09 at 12:48.

I think Womp has it ... Oh and while you are swapping your routes try routes. MapRoute(null, "HelpDesk/Ticket/Details/{TicketId}", new { controller = "Ticket", action = "Details"}) I think the , TicketId = "id" is messing things up Hope that helps, Dan.

Thanks Dan, that worked as well – robnardo Aug 17 '09 at 12:48.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions