我想在数据库上显示自动增量以创建视图。但在文本框上仍为“ 0”。我已经在数据库中设置了ID自动递增。我的语法没有错误,但ID不显示
此我的观点
<div class="form-group">
<label class="control-label col-md-2">ID ATS</label>
<div class="col-md-10">
@Html.EditorFor(model => model.id_ats, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.id_ats, "", new { @class = "text-danger" })
</div>
</div>
此我的控制器:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "id_ats, UniqueName, nama, prior_ex, start_date, end_date, coaching")] op_ats op_ats)
{
if (ModelState.IsValid)
{
db.op_ats.Add(op_ats);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(op_ats);
}
public ActionResult Create()
{
return View(op);
}
检查ID属性Identity=false,
Identity seed=0,
Identity Increment=0.
对于此问题,请将ID设置为Identity
然后检查ID属性Identity=true,
Identity seed=1,
Identity Increment=1.
If identity=true