我正在通過jquery ajax post將json數據發送給我的控制器操作。我的行爲中的IEnumerable一直爲空。模型聯編程序不會將json轉換爲IEnumerable <T>
是我的json錯誤或爲什麼模型聯編程序不能將json轉換爲IEnumerable?
public ActionResult Update(IEnumerable<Teststep> teststeps)
{
//
}
$.ajax({
url: '@Url.Action("Update", "Teststep")',
type: 'POST',
data: [{ "errortext": "oh something bad happended.", "unitid": "10" }, { "errortext": "you got it man.", "unitid": "20"}],
success: function (response) {
debugger;
if (response.success) {
dlg.dialog("close");
// Update UI
}
else {
// Reload the dialog with the form to show model/validation errors
dlg.html(response);
}
}
});
public class Teststep
{
[HiddenInput(DisplayValue = false)]
public int UnitId { get; set; }
public string ErrorText { get; set; }
// some other props removed for readability
}
嘗試使用**一步步測試[] teststeps **作爲參數的方法 和序列化JSON: JSON.stringity([{ 「ERRORTEXT」:「哦,東西「unitid」:「10」},{「errortext」:「你得到它的人。」,「unitid」:「20」}]) – cycaHuH
對不起,我沒有得到「嘗試使用Teststep []測試步驟爲...「你能重寫嗎? – Elisabeth
'公共ActionResult更新(Teststep [] teststeps)' – cycaHuH