How do I use an ActionLink with the RouteValueDictionary?

10k Views Asked by At

I'm trying to make my URL look like this:

http://domain.com/controller/action/123/SomeTextForSEO

I tried using an Action Link, but that appends ?company=SomeTextForSEO instead of the company name after a slash.

 <%: Html.ActionLink("DomainList", "Index", "DomainList", new { id = item.CompanyID, company = item.CompanyDisplayName.Trim() }, new object { })%> 

and now I think I need to use a RouteValueDictionary but I'm unsure of how to do this in ASP.NET syntax. Can someone point me in the right direction? The MSDN examples are insufficient.

1

There are 1 best solutions below

2
On BEST ANSWER

If you go to global.asax.cs and add a new route similar to the existing default route with the pattern

"{controller}/{action}/{id}/{company}"

Before the default one, you should find that the link will generate correctly with your ActionLink call as-is.

I'm on a phone so I'd like to be more verbose (a route restriction would be a good idea to prevent this route interfering with the default), but the HTC keyboard is not code friendly ;)