how to add item in db in asp.net mvc? [duplicate]

最后都变了- 提交于 2020-01-22 03:06:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!