我在asp.net MVC控制器中有以下方法,我的角度代码试图调用它:
[HttpPost]
public JsonResult SaveEducationList(List<InventoryGroupModel> inventoryEduList, int examId)
{
var listOfInventories = _examService.AddEduInventoryGroup(inventoryEduList);
return Json(listOfInventories);
}
我的角色代码叫做:
saveEduList: function (inventoryEduList, examId) {
return $resource('/mysite/Setup/SaveEducationList',
{ inventoryEduList: '@inventoryEduList', examId: '@examId' }, {
save: {
method: 'POST',
isArray: true
}
}).save(inventoryEduList, examId);
}
当调用这个角度方法时,我可以在Chrome的调试器中看到inventoryEduList和examId都被填充,但每当调用MVC方法时,都没有任何反应。 Fiddler表明它正在调用方法只是通过考试,没有别的。无论如何都要传递这两个参数吗?
答案 0 :(得分:1)
试试以下......
创建一个新类
public class SaveParam {
public List<InventoryGroupModel> InventoryEduList {get;set;}
public int ExamId {get;set;}
}
然后
[HttpPost]
public JsonResult SaveEducationList(SaveParam param)
{
var listOfInventories = _examService.AddEduInventoryGroup(param.InventoryEduList );
return Json(listOfInventories);
}
希望这个帮助