I don’t know whether I’m just stupid (don’t answer that!) or I’m fighting MVC routing but I have another problem.
In my Controller I do a RedirectToRoute(“ErrorRoute”) which renders a 404 View which has a MasterPage.
In the MasterPage I have a top navigation which has links such as /homepage and /news but when I am in the 404 View the navigation is /error/homepage and /error/news.
I have changed my route in Global.asax from this
routes.MapRoute(
"ErrorRoute", // Route name
"Error/Error404", // URL with parameters
new { controller = "Error", action = "Error404" }
);
to this
routes.MapRoute(
"ErrorRoute", // Route name
"Error/Error404", // URL with parameters
new { controller = "Error", action = "Error404" }
, new { action = "Error404" }
);
to see if that would help but I get a “No route in the route table..” error when I call RedirectToRoute
Can you please help?
Are your Links ActionLinks?
Use this:
EDIT
Oh, Add a new Route:
And repeat for news
ANOTHER EDIT
After reading the comments again, if your menu is on every page, what you should be is create a base controller:
Then all your Controllers (home, error) inherit this:
Then in your master page, loop through the ViewData[“menu”]:
Note: this is all from scratch, so there may be errors, but this is what I did on my last MVC project.