View not updating after post

前端 未结 3 1214
南方客
南方客 2020-12-01 07:33

I have a controller method CreateOrUpdate, this method is supposed to save the car to the database and then return as normal.

public ActionResult CreateOrUp         


        
相关标签:
3条回答
  • 2020-12-01 07:59

    I didn't want to clear the ModelState because I needed to display errors, so I went with

    ValueProviderResult vpr = new ValueProviderResult("", null, System.Globalization.CultureInfo.CurrentCulture);
    
    ModelState["id"].Value = vpr;
    
    0 讨论(0)
  • 2020-12-01 08:13

    it should be the ModelState problem. if you use Htmlhelper to Display id value. Default HtmlHelper display ModelState value not Model. Try display model value in view

    <td>
        @Model.id
    </td>
    

    or Clean ModelState Value in controller

    ModelState.Clear();
    

    or reset id value after SaveChange.

    theCar.Save();
    ModelState["id"].Value = theCar.id
    return View(theCar);
    

    Reset the value of textarea after form submission

    0 讨论(0)
  • 2020-12-01 08:20

    I added ModelState.Clear() to my HttpPost Controller method, as seen in this post Html helpers get data from model state and not from model if you return the same view after form post. to get updated data in the view use post redirect get pattern or ModelState.Clear() and it solved the problem.

    Thanks

    0 讨论(0)
提交回复
热议问题