2017-07-28 59 views
0

通過發佈到MVC控制器發送多個數據時出現問題 無論我通過發送的哪一步它都沒有被控制器接收,默認爲1,但它仍然會正確發送表單。如何發佈表單和字符串到MVC 4控制器

public class SetupP{ 
    public string fn {get;set;} 
    etc... 
} 

public ActionResult Start(int step = 1, Setup SetupP = null){ 
    if(step == 1) 
    if(step ==2) 
} 



$.post("/setup/Start", { step: 2, SetupP: $('#SetupForm').serialize() } 

回答

1

$('#SetupForm').serialize()返回查詢字符串如single=Single&check=check1&radio=radio1(從jQuery的.seialize()例子)。

因此{ step: 2, SetupP: $('#SetupForm').serialize() }會嘗試將整個查詢字符串顯示爲單個參數SetupP。這是一種混合數據格式,不起作用。

您可以手動一起把碎片,就像這樣:

$('#SetupForm').serialize() + '&step=2' 

或者,如果step值可以作爲一個變量,那麼:

$('#SetupForm').serialize() + '&step=' + someVariable 
+0

非常有幫助! – ArcSet

相關問題