ASP.NET MVC - How to maintain ModelState from a different controller?

后端 未结 5 2436
时光取名叫无心
时光取名叫无心 2021-02-20 18:43

I have a HomeController with an Index action that shows the Index.aspx view. It has a username/password login section. When the user clicks the submit button, it POSTs to a Lo

5条回答
  •  眼角桃花
    2021-02-20 19:18

    Use TempData to save state between requests. Use special attributes for convenience as shown here.

    Few moments to mention:

    • Don't return View directly from your POST-action, respect Post-Redirect-Get pattern.
    • Don't overuse TempData. It's only supposed to save model state right before redirect and to retrieve it right after being redirected.

提交回复
热议问题