1
Answer

Retain data after postback in mvc3

i have few drop down on view, on based on drop down some data filter from database.
 
my problem is that when i post form then value of drop down become null.
 

Answers (1)

0
Photo of Nataraj Gandhi Arunachalam
NA 439 110.9k 9y
Hi Sonu,
Since you are using MVC, the usual concepts we learn in ASP.NET web applications will not be applicable per se.
During MVC post, the best practice during form post is implement the PRG (Post Redirect Get) pattern to implement this kind of scenario. After posting your form, you need to redirect to your Get method so that you page will be loaded again with the required data (basically the drop down being filled again in your scenario).
Some examples of PRG pattern,
https://www.exceptionnotfound.net/the-post-redirect-get-pattern-in-asp-net-mvc/
https://www.stevefenton.co.uk/2011/04/asp-net-mvc-post-redirect-get-pattern/
http://sampathloku.blogspot.com/2013/05/how-to-use-prg-pattern-with-aspnet-mvc-4.html