【发布时间】:2013-11-30 07:01:33
【问题描述】:
在保存客户端名称时,它显示 clientID 的值为 null。 我尝试了很多,但无法得到解决方案。 这是代码:
控制器:
[SpecialAuthorize("Client_Add")]
public ActionResult Create()
{
var client = new OData.Client();
client.Picture = Guid.NewGuid().ToString();
SetMyBag(client);
return View("Edit", client);
}
[HttpPost]
[SpecialAuthorize("Client_Add")]
public ActionResult Create(OData.Client model)
{
var client = new OData.Client();
if (ModelState.IsValid == true)
{
db.Clients.Add(client);
db.SaveChanges();
db.LogHistory(new Activity(ActionEnum.Created, model.ClientId, model.ResellerName, model.ClientId, "Client"));
return RedirectToAction("Index");
}
SetMyBag(client);
return View("Edit", model);
}
【问题讨论】:
-
当表单从您的“编辑”视图提交时..它是否命中您的 create[Post] ActionResult?
-
aritra :是的,它命中了我的 PostActionResult。
-
@Iliya.Sullimanov :它始终将 clientID 显示为零。可能是什么?
标签: entity-framework asp.net-mvc-4 c#-4.0 ef-code-first entity-framework-5