AttributeRouting does not work

2019-07-19 21:23发布

问题:

I put [AttributeRouting.Web.Mvc.Route("faq.html")] on my action Faq.

However when I go to

localhost/faq.html 

I get a 404 http not found error and I can't find my custom routes in localhost/routes.axd.

How can i fix this ?

thanks !

updated: here is my faq action

    [OutputCache(Duration = 120)]
    [AttributeRouting.Web.Mvc.Route("faq.html")]
    public virtual ActionResult FAQ(int id = 0){
        //some code here 
    }

回答1:

Try code below:

[OutputCache(Duration = 120)]
[AttributeRouting.Web.Mvc.Route("faq.html/{id?}")]
public virtual ActionResult FAQ(int id = 0){
    //some code here 
}

or remove "id" parameter from FAQ method.

Explanation for AttributeRouting