0

我有点努力在 ASP.NET MVC4 中获取操作 url。

我正在使用以下剃刀语法创建一个链接:

@Html.ActionLink("some text", "Create", "Reports")

我得到的输出是:

<a href="/?action=Create&amp;controller=Reports">some text</a>

我想要的是:

<a href="/Reports/Create">some text</a>

任何想法,我错过了什么?

更新:

RouteConfig如下:

public static void RegisterRoutes(RouteCollection routes)
{
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

     // ignoring .aspx, .asmx files  
     routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
     routes.IgnoreRoute("{resource}.asmx/{*pathInfo}");

     routes.MapPageRoute("DefaultRoute", string.Empty, "~/Default.aspx");
     routes.MapPageRoute("MapsRoute", "Map", "~/Default.aspx");

     routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Reports", action = "Index", id = UrlParameter.Optional }
            );
}

第二次更新

如果我从路由配置中注释以下行,我会按预期获得 URL。知道为什么吗?

routes.MapPageRoute("DefaultRoute", string.Empty, "~/Default.aspx");
routes.MapPageRoute("MapsRoute", "Map", "~/Default.aspx");
4

1 回答 1

0

尝试这个

 @Html.ActionLink("some text", "Create", "Reports",null,null)

尝试添加route.config

routes.MapPageRoute("DefaultRoute", "{def}", "~/Default.aspx"); 
routes.MapPageRoute("MapsRoute", "{map}", "~/Default.aspx");

actionlink的基类如下:

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    Object routeValues,
    Object htmlAttributes
)
于 2014-02-20T09:44:54.393 回答