2014-09-24 58 views
0

我有這樣的jQuery方法Ajax的不傳遞字符串或陣列以MVC控制器

var params = { 
    pGroupIdents: $.param({ pGroupIdents: groupIdents }), 
    pIsNew: isNew, 
    pNewTypeCategoryIdent: $(DetailsNewTypeCategory_Select).val(), 
    pNewTypeTitle: $(DetailsNewTypeTitle_TB).val(), 
    pExistingTypeIdent: $(DetailsExistingTypeCategory_Select).val(), 
    pNote: isNew ? $(DetailsNewTypeNote_TB).val() : $(DetailsExistingTypeNote_Select).val() 
}; 
var json = JSON.stringify(params); 
$.ajax({ 
    url: "/Activities/PostExtraCurricular/SetExtraCurricular/", 
    type: "POST", 
    data: json, 
    dataType: "json", 
    processData: false, 
    contentType: "application/json; charset=utf-8" 
}) 
    .always(function() { 
    }) 
    .success(function (data) { 
    }) 
    .fail(function() { 
    }); 

發佈這種方法

public JsonResult SetExtraCurricular(Int32[] pGroupIdents, bool pIsNew, int pNewTypeCategoryIdent, String pNewTypeTitle, int pExistingTypeIdent, String pNote) 

而字符串化數據是這

"{"pGroupIdents":["12033","12025","12030"],"pIsNew":true,"pNewTypeCategoryIdent":"2","pNewTypeTitle":"title","pExistingTypeIdent":"2","pNote":"note"}" 

在控制器的參數int工作得很好,但String參數a nd Int32[]參數始終爲空。

我試過了;加入[HttpPost]traditional: truestring VS Stringint[] VS Int32[] VS IEnumerable[int]

香港專業教育學院所做的這一切只是前花花公子,但香港專業教育學院不知道什麼不在這裏

回答

0

解決,爲了這個,我創建了一個包裝類來傳遞我的變量,因爲我以前做過,但類似的問題這是在客戶端解決了parseInt(),我猜是問題也在這裏。

0

工作你不應該字符串化的PARAMS。通過對象發送很好。

$.ajax({ 
    url: "/Activities/PostExtraCurricular/SetExtraCurricular/", 
    type: "POST", 
    data: params, 
    dataType: "json", 
    processData: false, 
}) 
相關問題