Ajax 传参数到MVC

1、   传多个参数

var $this = $(this);
        var id = $this.attr("attrid");
        if (id <= 0) {
            return;
        }
        $.ajax({
            url: '/cabinlevelfare/delete',
            contentType: "application/json",
            type: 'POST',
            cache: false,
            dataType: 'json',
            data: JSON.stringify({ "id": id }),
            success: function (datas) {
                if (datas.IsSuccess) {
                    alert("删除成功");
                    window.location.href = "/cabinlevelfare";
                } else {
                    if (datas.Message == "") {
                        datas.Message = "删除失败";
                    }
                    alert(datas.Message);
                }
            }
        });

2、传对象

  
    var model = {
        StartingCity: $.trim(startingCity),
        ArrivedCity: $.trim(arrivedCity),
        Sales: $.trim(sales),
        MonetaryCode: $.trim(monetaryCode),
        RouteType: $.trim(routeType),
        ConcurrentRestriction: $.trim(concurrentRestriction),
        Status: status
    };

    var sendData = { OneGApiModel: model };
    clear();
    $.ajax({
        type: "POST",
        contentType: "application/json",
        dataType: "text",
        url: "/OneGAPI/Input",
        data: JSON.stringify(sendData),
        success: function (data) {
            alert(data);
        },
        error: function (msg) {
            alert(msg);
        }
    });

原文地址:https://www.cnblogs.com/xiaocandou/p/4528583.html