3

我有一个名为article的控制器,我在 url 中的文章采用{controller}/{action}/{id}/{title}/{mixed}的形式,我怎样才能将它发送到{controller}/{id}/{标题}/{混合}

我的路线价值是

routes.MapRoute(
            "articles", 
            "{controller}/{action}/{id}/{stitle}/{mixed}", 
  new { controller = "article",action="detail",mixed= UrlParameter.Optional} // Parameter defaults

        );

我试过这个

 routes.MapRoute(
            "articles", // Route name
            "{controller}/{id}/{title}/{mixed}",
  new { controller = "article",action="detail",mixed= UrlParameter.Optional}

        );

但得到一个 404 错误,因为我的链接在表单中

@Html.ActionLink("My article", "detail", "article", new { id = item.ArticleID, title = item.title, mixed = item.mixed })
4

1 回答 1

2
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapRoute(
        "ArticleWithoutAction",              // Article Without Action name
        "{controller}/{id}/{name}", 
        new { controller = "Article", 
              action     = "detail", 
              id         =  UrlParameter.Optional, 
              title      =  UrlParameter.Optional, 
              mixed      =  UrlParameter.Optional
            } // Parameter defaults
    );

    routes.MapRoute(
        "ArticleWithAction",                  // Article With Action name 
        "{controller}/{action}/{id}/{name}", 
        new { controller = "Article", 
              action     = "detail", 
              id         =  UrlParameter.Optional, 
              title      =  UrlParameter.Optional, 
              mixed      =  UrlParameter.Optional
            } // Parameter defaults
    );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}", 
        new { controller = "Article", 
              action     = "detail" 
            } // Parameter defaults
    );
}
于 2013-06-11T18:10:31.580 回答