C# ASP-MVC实体框架更新记录,如果仅附加原始数据以外的字符,则不会更新

C# ASP-MVC实体框架更新记录,如果仅附加原始数据以外的字符,则不会更新,c#,asp.net,asp.net-mvc,entity-framework,C#,Asp.net,Asp.net Mvc,Entity Framework,我有一个更新记录的问题,只有当编辑文本框中的原始数据被一个新值完全更改时,它才会更新记录。例如,如果原始值为“Apple”,并且仅附加了“S”以成为“Apples”,则不会更新。它仅在整个单词更改时更新。我使用实体框架为我创建的表创建数据模型,并为编辑表单视图使用编辑脚手架模板。你能帮我做这个吗 以下是我在编辑控制器操作中的代码: public ActionResult Edit(int? Id) { // if (Id == null) // {

我有一个更新记录的问题,只有当编辑文本框中的原始数据被一个新值完全更改时,它才会更新记录。例如,如果原始值为“Apple”,并且仅附加了“S”以成为“Apples”,则不会更新。它仅在整个单词更改时更新。我使用实体框架为我创建的表创建数据模型,并为编辑表单视图使用编辑脚手架模板。你能帮我做这个吗

以下是我在编辑控制器操作中的代码:

public ActionResult Edit(int? Id)
    {
       // if (Id == null)
       // {
           // return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
       // }
        Book student = stud.Books.Find(Id);
        //if (student == null)
        //{
           // return HttpNotFound();
       // }
       return View(student);
    }
    //edit2
    [HttpPost, ActionName("Edit")]
    [ValidateAntiForgeryToken]
    public ActionResult EditPost(int? Id)
    {
        //if (Id == null)
        //{
           //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //}
        var studentToUpdate = stud.Books.Find(Id);
        if (TryUpdateModel(studentToUpdate, "",
           new string[] { "BookTitle", "Author"}))
        {
            try
            {
                if (ModelState.IsValid)
                {


                    stud.SaveChanges();

                    return RedirectToAction("Index");
                }
            }
            catch
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }
        }
        return View(studentToUpdate);
    }
请看它可能对你的案子有帮助。