Подтвердить что ты не робот

Сериализация почтовой формы ASP.NET MVC JQuery Ajax?

Функция Ajax

$(function () {
    $('form').submit(function () {
        if ($(this).valid()) {
            $.ajax({
                url: this.action,
                type: this.method,
                data: { model: $(this).serialize(), locations: getCheckedLocation(), reports: getCheckedReports() },
                beforeSend: function () {

                },
                complete: function () {

                },
                success: function (result) {
                    $('#user_operations_container').html(result);
                    setTimeout(function () { LoadAction('@Url.Action("GetAllUsers", "User")') }, 1000);
                    $("#widgets ul li a").removeClass("link_active");
                    $("#widgets ul li:first-child a").addClass("link_active");
                }
            });
        }
        return false;
    });
});

которые используются в атрибуте данных ajax

function getCheckedLocation() {
    var nodes = $('#tt_location').tree('getChecked');
    var s = '';
    for (var i = 0; i < nodes.length; i++) {
        if (s != '') s += ',';
        s += nodes[i].text;
    }
    return s;
}

function getCheckedReports() {
    var nodes = $('#tt_reports').tree('getChecked');
    var s = '';
    for (var i = 0; i < nodes.length; i++) {
        if (s != '') s += ',';
        s += nodes[i].text;
    }

    return s;
}  

HTML

<div> // there are html helpers for model (dropdownlistfor, textboxfor,...)
</div>
<div> // checkbox tree (#tt_location)
</div>
<div> // checkbox tree (#tt_reports)
</div>

контроллер

[HttpPost]
public ActionResult _EditUser(UserViewModel model,string locations,string reports)
{
    // model = null
    // locations and reports are expected. (not null)
}

Вопрос

Почему модель равна нулю? Когда я использую атрибут данных ajax, например this = data: $(this).serialize(),, он работает с моделью не null.

Как я могу опубликовать модель с дополнительными данными (местоположениями, отчетами).

Надеюсь, я могу объяснить. Спасибо...

4b9b3361

Ответ 1

Попробуйте вот так:

 data:$('this').serialize() + "&locations=" + getCheckedLocation() "&reports=" + getCheckedReports() 

Он будет работать.

Надеюсь, что это поможет