如何在mvc3中点击按钮时加载部分视图

时间:2011-09-26 19:03:49

标签: asp.net-mvc-3 partial-views

我有一个DDL,在其更改时我加载了部分视图_GetX。现在我正在使用它

   @Html.DropDownListFor(model => model.XId, Model.XList, "Select", new { GetUrl = Url.Action("GetX", "Route") })

我需要在点击按钮时加载此部分视图。我该怎么做?

1 个答案:

答案 0 :(得分:0)

假设您的GetX控制器操作已经返回部分视图:

$(function() {
    $('#someButton').click(function() {
        // get the DDL. It would be better to add an id to it
        var ddl = $('#XId');

        // get the url from the ddl
        var url = ddl.attr('GetUrl');

        // get the selected value of the ddl to send it to the action as well
        var selectedValue = ddl.val();

        // send an AJAX request to the controller action passing the currently
        // selected value of the DDL and store the results into
        // some content placeholder           
        $('#somePlaceholder').load(url, { value: selectedValue });

        return false;
    });
});