即使我对值进行硬编码,也没有插入任何内容。我可以使用创建 Transaction 类时创建的方法,还是必须为 ajax 调用编写自定义方法?
jQuery/ajax 调用
$("#SubmitTransaction").on("click", function () {
var div = $("#AddedItems");
var uid = $("#getUser").attr("data-logName");
var TUid = $("#uid").attr("data-tID");
var TId = $('#TiD').attr("data-tID");
var ids = $("#AddedItems li").map(function () { return this.id }).get();
var trade = {
FromUserID: uid,
TID: TUid,
itemTForId: TItemId,
items: ids
}
$.ajax({
type: "POST",
url: "/Transaction/Create",
data: trade
});
});
控制器:我想如果我通过了Transaction
就可以了
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(Transactions transaction)
{
if (ModelState.IsValid)
{
db.Transactions.Add(transaction);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(transactions);//not really concerned with where it goes right now
} //just want to get the values in the db
交易模式
public class Transactions
{
// all the properties
//
//
public ICollection<Item> items { get; set; }//this is not being stored
}