2013-05-08 71 views
1

嗨我想刷新多個參數的局部視圖。我已經得到它與一個參數一起工作。我怎樣才能讓它使用多個參數。這是代碼,我到目前爲止。 VIEW刷新多個參數的局部視圖

@{ 
    ViewBag.Title = "Report"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

<script type="text/javascript"> 
    $(document).ready(function() { 

     $("#serviceLine").change(function() { 
      var url = "/Home/PartialView1?serviceLine=" + $(this).val(); 
      alert(url); 
      $("#reportContent").load(url); 
     }); 

     $("#ClientID").change(function(){ 
      var url = "/Home/PartialView1?ClientID=" + $(this).val(); 
      alert(url); 
      $("#reportContent").load(url); 
     }); 
    }); 
</script> 

<h3>Report</h3> 
<div> 
    <table> 
     <tr> 
      <td>Client</td> 
      <td>@Html.DropDownList("ClientList", null, new {id = "ClientID"})</td> 
      <td>ServiceLine</td> 
      <td>@Html.DropDownList("ServiceLine", null, new {id="serviceLine"}) </td> 
</td> 
     </tr> 
    </table> 
</div> 
<div> 
    <h2>List</h2> 
    <div id="reportContent"> 
     @Html.Action("PartialView1", new { clientID = 0, serviceLine = "_" }) 
    </div> 
</div> 

控制器

public ActionResult PartialView1(int clientID, char serviceLine) 
     { 
      //Login 

      return PartialView(); 
     } 

有什麼建議嗎?

+0

** [Check here](http://stackoverflow.com/a/16245682/2007801)** – 2013-05-08 12:08:29

回答

0

你可以試試這個:

$.ajax({ 
    url: "Home/PartialView1", 
    type: 'POST', 
    data: { "clientID": myclientId, "serviceLine" : myServiceLine } 
}).done(function (data) { 
    div("#reportContent").html(data); 
}); 

只要把所有的參數數據屬性。

0

您可以使用jQuery ajax方法並從success方法中填充結果。例如:

$.ajax({ 
    url: "@Url.Action("PartialView1", "Home")", 
    type: "POST", 
    data: { clientID: $("#ClientID").val(), serviceLine: $("#serviceLine").val() }, 
    success: function (result) { 
     $("#reportContent").html(data); 
    } 
});