I know this has been asked before but I’m really struggling with the concept of route configs in MVC – specifically removing controller names and/or action names from a URL.
On my webpage, I have a partial view called “Sidebar”, which uses its own controller (SidebarController).
Within the sidebar’s partial view, I have the following ActionLink:
@Html.ActionLink("December-2012", "Archive", new { id = "December-2012" })
When the link is built, the URL reads as
http://localhost/Sidebar/Archive/December-2012
My problem is having the “Sidebar” part appearing in the URL – this controller isn’t technically used for any navigation; it’s just used to build the partial view. Instead, I want the URL to read:
http://localhost/Archive/December-2012
I tried specifying the controller on the ActionLink, but this just results in
http://localhost/Archive/Archive/December-2012
Could somebody please explain (in simpleton terms) how I configure a route so that when /Archive is put on the end of the URL, it knows to call the ArchiveController with (let’s say) the Index(id) action?
Thanks in advance, and apologies for asking a question that’s been covered before – as I said I’m just really struggling with the whole concept of route maps.
Not entire sure what your doing wrong here. Perhaps also include the code for the second url.
You could use this overload of the Html.ActionLink method:
You would use it like this:
Which will produce the following url:
Update:
Based on your comment you need this route above your default route:
And the same action link should map to this url:
Remember the route has to be above the Default route.
This url should then work: