开发者

ASP.NET MVC2 Route Mapping ignore action and id

开发者 https://www.devze.com 2023-01-19 21:03 出处:网络
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.

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" }
);
0

精彩评论

暂无评论...
验证码 换一张
取 消