62,046
社区成员
发帖
与我相关
我的任务
分享
function CreateNew() {
var auc = { "Title": "Hello6", "Description": "商品6", "StartPrice": "5.00", "CurrentPrice": "10.00", "StartTime": "2014/01/01", "EndTime": "2014/03/05" };
//$.ajax({ //这种在Control中的参数映射不到值,why?
// type: 'POST',
// url: '/Auction/Create',
// data: { "auction": auc },
// dataType: "json",
// success: function (data) {
// },
// error: function (XMLHttpRequest, textStatus, errorThrown) {
// alert('error');
// }
//});
$.post('Auction/Create', auc, function (data) { alert(data['Title']); }, 'json');
}
[HttpPost]
public ActionResult Create(Auction auction)
{
if (ModelState.IsValid)
{
db.Auctions.Add(auction);
int i = db.SaveChanges();
if (Request.IsAjaxRequest())
{
return Json(auction);
}
return RedirectToAction("Show");
}
return View(auction);
}
[HttpPost]
public ActionResult Create(Auction auction)
{
if (ModelState.IsValid)
{
db.Auctions.Add(auction);
int i = db.SaveChanges();
//if (Request.IsAjaxRequest())
//{
// return Json(auction);
//}
return RedirectToAction("Show");
}
return View(auction);
}