AttributeRouting does not work

烂漫一生 提交于 2019-12-24 01:59:35

问题


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



来源:https://stackoverflow.com/questions/10646580/attributerouting-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!