我有一个下面的代码,问题是当我第一次添加项目时,然后我向模型添加ID。再次,我单击同一按钮编辑我的模型ID为null的东西。丢失了,我已经分配了ID值
@using (Html.BeginForm("BusinessOrderAdd", "BusinessOrder", FormMethod.Post, new { @id = "bsCurrForm" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id)
@Html.LabelFor(model => model.Name, "Name", htmlAttributes: new { @class = "control-label col-md-2" })
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult BusinessOrderAdd(myDTO myorder)
{
myorder.Id = Guid.NewGuid();
return Json(myorder, JsonRequestBehavior.AllowGet);
}
public ActionResult BusinessOrderAdd()
{
try
{
myorder.Date = DateTime.Now;
myorder.StartTime = DateTime.Today.Date.AddHours(12);
//some properties here.
}
catch (Exception ex)
{
throw;
}
return PartialView("_AddOrEditBusinessOrder", myorder);
}