2011-05-06 58 views
0

我希望我已經提供了足夠的信息給有人幫助。我有一個jQuery的模板,其中是一個鏈接,返回一個id到一個ActionResult。 我的問題是:添加另一個參數到鏈接的語法是什麼,所以ActionResult接收兩個參數。使用MVC在jQuery模板中添加兩個參數到href

<script id="searchTemplate" type="text/x-jquery-tmpl"> 
    <a href="/Search/Details/${JournalId} WHAT GOES HERE? "> 
</script> 

public ActionResult Details(int id, string otherParameter) 
    { 
     var item = ctx.Journals.Find(id); 
     return View("Details", item); 
    } 

回答

1
<script id="searchTemplate" type="text/x-jquery-tmpl"> 
    <a href="/Search/Details/${JournalId}?otherParameter=value"> 
</script> 
+0

完美!謝謝DanielB – 2011-05-06 13:17:37

0

是的,這會工作,但在MS MVC中的「最佳實踐」的方式是建立在Global.asax一條新路線。

public static void RegisterRoutes(RouteCollection routes) 
{ 
// callable like this: <a href="/Search/Details/${JournalId}/value"> 
routes.MapRoute(
      "MyNewRouteName", 
      "MyController/SomeCoolAction/{id}/{otherParameter}", 
      new { controller = "MyController", action = "SomeCoolAction"} 
      ); 

.... 
} 
相關問題