发布到控制器时,图像值为null

时间:2016-09-21 09:01:04

标签: javascript ajax asp.net-mvc

控制器映像中的

来自null我尝试了这段代码,但它无法正常工作

function bindForm(dialog) {

$("form", dialog).submit(function () {
    var formdata = new FormData($('form').get(0));
    $.ajax({
        url: "/Books/Create",
        type: "POST",
        dataType: "JSON",
        data: formData,
        contentType: false,
        processData: false,
        success: function (result) {
            if (result.success) {
                $("#myModal").modal("hide");
                location.reload();
            } else {
                $("#myModalContent").html(result);
                bindForm();
            }
        }
    });
    return false;
});
}

1 个答案:

答案 0 :(得分:0)



$(function () {

    $.ajaxSetup({ cache: false });

    $("a[data-modal]").on("click", function (e) {
        $("#myModalContent").load(this.href, function () {
            

            $("#myModal").modal({
                keyboard: true
            }, "show");

            bindForm(this);
        });

        return false;
    });
});

function bindForm(dialog) {
    
    $("#crtForm", dialog).submit(function () {
        var myform = document.getElementById("crtForm");
        var fdata = new FormData(myform);
       $.ajax({
            url: this.action,
            data: fdata,
            cache: false,
            processData: false,
            contentType: false,
            type: "POST",
            success: function (result) {
                if (result.success) {
                    $("#myModal").modal("hide");
                    location.reload();
                } else {
                    $("#myModalContent").html(result);
                    bindForm();
                }
            }
        });
        return false;
    });
}