Best way to create a Form in MVC (aspnet 6)

Question: How do you create a form that is pesists data on ModelState validation?
Answer: When designing a form it is very important to remember that it can be a key to having a painless data entry to your application. 

Good Practices when dessigning a form
1. Make sure that your form remembers data entered into fields when model is invalid.
    - This is very important as it allows users to only correct the mistakes on the form and not to enter all the fields again.
2. Send clear message on what is needed to be done in order for the form to be valid.
     - Do not show confusing messages or text to the user, as this may cause frustrations to the end user.

How to persist data to the form in MVC AspNet 5 Razor View
1. Create the form with input fields
2. Let the form submit to a function/Action marked for HTTPPost verb
3. Check if the Model is valid by using the code below
 ModelState.Clear();//This is important as you would want to return the very model with current data so that 
//the user doesn't have to enter data twice.
   return View(model);

Edit this Article
Form not remembering data in MVC Razor Page not refreshing Razor Runtime Compilation .NET 6 published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.
Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy