I want show the auto increment on database to Create View. But on the textbox it is still '0'. I have already set the Id field to auto increment in database.
There's no error in my syntax but the id does not show.
This my View:
<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>
This my Controller:
[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);
}
This is the image of my view:
This image is of my database:
But I am still confused with the controller.
check Id properties Identity=false, Identity seed=0, Identity Increment=0.
For this problem , set the Id as the Identity
Then check Id properties Identity=true, Identity seed=1, Identity Increment=1. If identity=true
Identity=true, Identity seed=1, Identity Increment=1. If identity=true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.