问题
all item from "view" send to "ActionResult Create"
so we want to quantify "matchid" and "userid" from the server side
but srver side's validation errors and it dosen't let the program add data in database.
also if we comment "(ModelState.IsValid)" the program will run corectly but we need this.
what shoud we do?
public ActionResult Create([Bind(Include = "id,creatdate,bugname,title,attach")] Reports reports)
{
if (ModelState.IsValid)
{
reports.matchid = mactchid;
reports.userid = User.Identity.GetUserId();
db.Reports.Add(reports);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(reports);
}
来源:https://stackoverflow.com/questions/59411536/how-to-add-item-in-db-in-asp-net-mvc