2013-05-09 84 views
1

我得到了下面的Ajax ActionLink的在我的CSHTML页:如何使用Ajax.ActionLink而不更新URL

@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,而通过Specific而不是具体的方法。我如何确保Specific()被调用,而不更新url?

+0

的问题是,路由模式匹配'{控制器}/{action}' – mattytommo 2013-05-09 14:45:58

回答

1

就像这样。玩这个命令。

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

因此,显式创建Events/Specific的路由来覆盖概览路由?正如我上面的回答。 – 2013-05-09 14:54:17

+0

更好,我为你解决了:)。该行动是“具体”**而不是“具体”。 – mattytommo 2013-05-09 14:54:48

+0

谢谢。 :)我刚看到错误。 – 2013-05-09 14:55:17

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) 
相关问题