Avoid the cache data in ASP.NET MVC raizor page

The MVC view data cache is good but sometime we just want to reset the page’s value with binding Model, and you will find the value can not be reset, such link in a search form with the criteria.

For example, you want to reset all the criteria fields to default (not empty) as below

but you will find that’s not working, the date values are still keep as the user’s input values, the problem is the Views page will auto cache the binding Model value, so you need to use ModelState.Clear(); to clear the model state when you reset the model value:

and this time will be working fine!

 422 total views,  2 views today

Share your vote!


Do you like this post?
  • Fascinated
  • Happy
  • Sad
  • Angry
  • Bored
  • Afraid

You may also like...