Refresh partial view with multiple parameters

2019-06-01 08:39发布

Hi I am trying to refresh partial view with multiple parameters. I have got it to work with one parameter. How can I get it to work with more than one parameters. Here is the code, I have got so far. 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>

CONTROLLER

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

            return PartialView();
        }

ANY SUGGESTIONS PLEASE?

2条回答
倾城 Initia
2楼-- · 2019-06-01 08:53

You could try this:

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

Just put all of the parameters in the data property.

查看更多
Summer. ? 凉城
3楼-- · 2019-06-01 09:02

You can use a jQuery ajax method and populate the results from the success method. Something like:

$.ajax({
    url: "@Url.Action("PartialView1", "Home")",
    type: "POST",
    data: { clientID: $("#ClientID").val(), serviceLine: $("#serviceLine").val() },
    success: function (result) {
        $("#reportContent").html(data);
    }
});
查看更多
登录 后发表回答