2014-02-07 95 views
0

我有一個Ajax.ActionLink在局部視圖如下:Ajax.ActionLink只有鏈接到當前頁面

<div id="accordion"> 
    @foreach (var m in Model) 
    { 
     var targetId = m + "_List"; 

     <h3 id="@(m)" class="thingModelHeader"> 
      @Ajax.ActionLink(m, "AjaxGetThings", "Perf", 
       new AjaxOptions { 
        HttpMethod="GET", 
        InsertionMode = InsertionMode.Replace, 
        UpdateTargetId= targetId, 
        Url="13412" 
       }) 
     </h3> 
     <div id="@targetId" > 
      @* list will populate here when the link is clicked *@ 
     </div> 

    } 
</div> 

我有適當的方法控制器:

public class PerfController : Controller 
{ 
    [Route("AjaxGetThings/{id}", Name = "AjaxGetThings")] 
    public PartialViewResult AjaxGetThings(string id) 
    { 
     IQueryable<Thing> results; 

     using (var repo = new ReadOnlyRepository<Thing>()) 
     { 
      things = repo.All() 
          .Where(p => p.Id == Id) 
          .OrderBy(p => p.Name) 
          ; 
     } 

     return PartialView("CustomPartialView", results); 
    } 

} 

我有在不顯眼的驗證一個ScriptBundle:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
    "~/Scripts/jquery.unobtrusive*", 
"~/Scripts/jquery.validate*")); 

...我引用它在我的佈局頁:

</footer> 
    @Scripts.Render("~/bundles/jquery") 
    @Scripts.Render("~/bundles/jquery-ui") 
    @Scripts.Render("~/bundles/jqueryval") 
    @RenderSection("scripts", required: false) 
    </body> 
</html> 

問題是無論我如何在AjaxOptions中定義Action,Controller或Url,鏈接始終指向當前URL。目標div加載並更新整個頁面 - 所以它的工作只要它的Ajax部分,但不管我做了什麼,URL永遠不會指向任何有用的地方 - 如實際的控制器和操作我已經指定。

回答

0

嘗試指定這樣

url: 'Url.Action("Action", "Controller", new { ID = m.targetid })' 
+0

我怎麼通過ID成上的網址? –

+0

將它添加爲html屬性,請參閱我的編輯 –

相關問題