ASP.NET MVC2 Route Mapping ignore action and id
I'm trying to add a FAQ section to a website that I'm working on and I want to ignore any action or id that is added to the URL.
The RegisterRoutes method of the Global.asax.cs file has been changed to;
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"FAQ",
"FAQ",
new {controller = "FAQ", action= "Index"});
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
The FAQController.cs looks like this;
public class FAQController : Controller
{
private FAQModel _faq = new FAQModel();
public ActionResult Index()
{
return View(_faq.GetFAQ());
}
}
But this doesn't appear to be working, I was 开发者_StackOverflow中文版wondering whether anyone could point me in the right direction of how to do this.
Thanks for any help in advance
Satal :)
Try this:
routes.MapRoute(
"FAQ",
"FAQ/{*pathInfo}",
new { controller = "FAQ", action = "Index" }
);
精彩评论