页面刷新后,模型项丢失了C#MVC

时间:2019-05-22 11:44:31

标签: c# asp.net asp.net-mvc

我有一个下面的代码,问题是当我第一次添加项目时,然后我向模型添加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);
}

GET方法

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);
}

0 个答案:

没有答案