HttpVerbs.Get和参数?

时间:2012-11-26 18:13:15

标签: c# asp.net-mvc routing

我有以下行动:

public class IntegrationController : Controller
    {
        [AcceptVerbs(HttpVerbs.Get)]
        public ContentResult Feed(string feedKey)
        {
           ...
        }
}

我试图使用此网址:

http://MyServer/Integration/Feed/MyTest 

feedKey为空?这与路线有关吗?

编辑1:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Ad", action = "List", id = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "TreeEditing", // Route name
                "{controller}/{action}/{name}/{id}", // URL with parameters
                new { controller = "AdCategory", action = "Add", name = string.Empty, id = -1 }
            );

编辑2:

routes.MapRoute(
                "IntegrationFeed", // Route name
                "{controller}/{action}/{name}/{feedKey}", // URL with parameters
                new { controller = "Integration", action = "Feed", name = string.Empty, feedKey = "" }
            );

1 个答案:

答案 0 :(得分:1)

您是否为feedKey定义了路线?使用默认路由时,以下内容应该有效(将feedKey更改为id)。

    [AcceptVerbs(HttpVerbs.Get)]
    public ContentResult Feed(string id)
    {
       // ...
    }