Как загрузить частичное представление по нажатию кнопки в MVC3 - PullRequest
1 голос
/ 26 сентября 2011

У меня есть DDL, при его изменении я загружаю частичное представление _GetX.Прямо сейчас я использую это так

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

Мне нужно загрузить это частичное представление при нажатии кнопки.Как мне это сделать?

1 Ответ

0 голосов
/ 26 сентября 2011

Если ваше действие контроллера 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;
    });
});
...