標籤:hand eid post str code count 自增 style 後台
接收的實體
public class AccountInfo { public int TicketType { get; set; } public int TouristType { get; set; } public string SpotID { get; set; } public int TicketNum { get; set; } }
ajax傳輸的資料
JiLu["JL[" + y + "].TicketType"] = parseInt($(SpotID[y].TypeID).val()); JiLu["JL[" + y + "].TouristType"] = parseInt($(SpotID[y].TouristID).val()); JiLu["JL[" + y + "].SpotID"] = SpotStr; JiLu["JL[" + y + "].TicketNum"] = parseInt($(SpotID[y].NumID).val());
$.ajax({
url: "/SalesTicket/Single/AccountMoney",
dateType: ‘json‘,
type: ‘Post‘,
data: JiLu,
async: false,
success: function (data) {
}
})
{"JL[0].TicketType":2,"JL[0].TouristType":-1,"JL[0].SpotID":"Spot,2","JL[0].TicketNum":1,"JL[1].TicketType":1,"JL[1].TouristType":-1,"JL[1].SpotID":"Spot,2,3,1","JL[1].TicketNum":1}
如果資料格式為 {LJ:[...]} 則controller只可以收到條數,資料為null
而且索引必須為0開頭的自增數,不然接收資料錯亂
後台Controller
[HttpPost] [HandlerAjaxOnly] public ActionResult AccountMoney(List<AccountInfo> JL) { foreach (var x in JL) { } return Json(null); }
MVC Controller接受ajax post傳輸的List<Entity>資料