开发者

Detection of page refresh / F5 key in ASP.NET MVC 2

开发者 https://www.devze.com 2023-01-01 04:26 出处:网络
How would one go about detecting a page refresh / F5 key push on the controller handling the postback?I need to distinguish between the user pressing one of two buttons (e.g., Next, Previous) and when

How would one go about detecting a page refresh / F5 key push on the controller handling the postback? I need to distinguish between the user pressing one of two buttons (e.g., Next, Previous) and when the F5 / page refresh occurs.

My scenario is a single wizard page that has different content shown between each invocation of the开发者_如何转开发 user pressing the "Next" or "Previous" buttons. The error that I am running into is when the user refreshes the page / presses the F5 key, the browser re-sends the request back to the controller, which is handled as a post-back and the FormCollection type is used to look for the "submitButton" key and obtain its value (e.g., "Next," "Send"). This part was modeled after the post by Dylan Beattie at How do you handle multiple submit buttons in ASP.NET MVC Framework?.

Maybe I'm trying to bend MVC 2 to where it isn't meant to go but I'd like to stay with the current design in that the underlying database drives the content and order of what is shown. This allows us to add new content into the database without modifying the code the displays the content.

Thanks, Michael


The recommended way is to use PRG pattern - Post-Redirect-Get. Meaning: after submitting, redirect a client to Index or what, causing only reloading Index when user hits F5, not posting the data again.

Check this: http://en.wikipedia.org/wiki/Post/Redirect/Get

And this: http://www.google.sk/search?q=prg+mvc+asp.net

0

精彩评论

暂无评论...
验证码 换一张
取 消