AttributeRouting不起作用 [英] AttributeRouting does not work

查看:255
本文介绍了AttributeRouting不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把 [AttributeRouting.Web.Mvc.Route(的faq.html)] 我的行动的常见问题。

然而,当我去

 本地主机/ faq.html常见问题

我得到一个404 HTTP未找到错误,我无法找到本地主机/ routes.axd我的自定义路线。

我怎样才能解决这个问题?

谢谢!

更新:
这里是我的帮助作用

  [的OutputCache(持续时间= 120)]
    [AttributeRouting.Web.Mvc.Route(的faq.html)]
    公共虚拟的ActionResult FAQ(INT ID = 0){
        //一些code在这里
    }


解决方案

尝试下面code:

  [的OutputCache(持续时间= 120)]
[AttributeRouting.Web.Mvc.Route(的faq.html / {ID?})]
公共虚拟的ActionResult FAQ(INT ID = 0){
    //一些code在这里
}

或常见问题的方法去除ID参数。

解释AttributeRouting

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 
    }

解决方案

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

这篇关于AttributeRouting不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆