刷新多个参数的局部视图 [英] Refresh partial view with multiple parameters

查看:118
本文介绍了刷新多个参数的局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试刷新多个参数的局部视图。我有它一个参数来工作。我怎样才能得到它与多个参数的工作。下面是代码,我已经这么远。
VIEW

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>



控制器

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

            return PartialView();
        }

有什么建议吗?

推荐答案

您可以使用jQuery的AJAX方法和填充从成功方法的结果。是这样的:

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);
    }
});

这篇关于刷新多个参数的局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆