簡體   English   中英

使用Ajax的MVC發布表單和MVC控制器的額外參數

[英]MVC posting form and extra param to an MVC controller using Ajax

我需要找到一種方法來通過ajax請求將序列化表格和額外的參數發布到控制器。 我可以在窗體上使用serialize() ,也可以僅發送帶有參數的對象,但不能同時發送兩者。 我將如何完成?

例如,我希望控制器參數如下:

myaction(int siteID, Model model).

傳遞所需的額外參數以及表單數據,如下所示:

 $.ajax({     type: 'POST',  
                 url: "/MyController/Process",
                 data: $("form").serialize() + '&id=12345' ,   
                 success: function () { alert("Successful"); },     
                 dataType: "json" 
    }); 

希望這可以幫助..

您需要使用以下內容:

var dataToPost = $('#formID').serialize() + "&siteID=" + "23";

現在像這樣在jquery ajax方法中使用此dataToPost變量:

 $.ajax({
            url: //url,
            type: //'POST',
            dataType: //'html',
            async: true,
            data: dataToPost,
            cache: false,
        }).success(function (response, status, xhr) {

        }).fail(function (e) {
            console.log(e);
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM