asp.net mvc的自动增量ID数据库

问题描述 投票:0回答:1

我想在数据库上显示自动增量以创建视图。但在文本框上仍为“ 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);
        }

此图片我的观点enter image description here此图像我的数据库enter image description here但是我仍然对控制器感到困惑请帮助我,非常感谢

c# asp.net auto-increment id
1个回答
0
投票

检查ID属性Identity=false, Identity seed=0, Identity Increment=0.对于此问题,请将ID设置为Identity

然后检查ID属性Identity=true, Identity seed=1, Identity Increment=1. If identity=true

© www.soinside.com 2019 - 2024. All rights reserved.