1

我在我的 cshtml 页面中获得了以下 Ajax Actionlink:

@Ajax.ActionLink("Sort By Date",
                "Specific",
                "Events",
                new AjaxOptions {
                    UpdateTargetId="EventListContainer",
                    InsertionMode=InsertionMode.InsertAfter,
                    HttpMethod="GET"
                })

我在控制器中得到了这两种方法:

public ActionResult Overview(string user)
{
    // return PartialView here
}

public PartialViewResult Specific()
{
    // return PartialView here
}

使用以下路线:

routes.MapRoute(
  name: "EventsRoute",
  url: "Events/{user}",
  defaults: new { controller = "Events", action = "Overview" }
);

现在,每次我调用 Ajax 方法时,Overview都会被调用,其中带有SpecificPassed,而不是特定方法。如何确保在不更新 url 的情况下调用 Specific()?

4

2 回答 2

1

像这样的东西。玩弄排序。

routes.MapRoute(
  name: "EventsSpecificRoute",
  url: "Events/Specific",
  defaults: new { controller = "Events", action = "Specific" }
);
于 2013-05-09T14:48:35.157 回答
0

创建新路线

routes.MapRoute(
  name: "EventSpecific",
  url: "Events/{user}",
  defaults: new { controller = "Events", action = "Specific" }
);

当您使用自定义路线时,我建议您使用RouteLink而不是ActionLink

@Ajax.RouteLink("Sort By Date","EventSpecific", new AjaxOptions {  
                    UpdateTargetId="EventListContainer",
                    InsertionMode=InsertionMode.InsertAfter,
                    HttpMethod="GET"}, null)
于 2013-05-09T15:20:33.987 回答