Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4601304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:48:22+00:00 2026-05-21T23:48:22+00:00

Is there any best practice for PRG pattern with MVC? In this tutorial: http://www.theserverside.com/news/1365146/Redirect-After-Post

  • 0

Is there any best practice for PRG pattern with MVC?
In this tutorial:
http://www.theserverside.com/news/1365146/Redirect-After-Post
the proposed solution requires 4 actions:
Create_Item (POST) => “resets” the form and redirects to Display_Item
Display_Item (GET) => shows the form (with temp data and errors if exists)
Store_Item (POST) => try to save data to DB, if errors, save errors and redirect to Display_Item, if success redirect to Display_Stored
Display_Stored (GET) => shows the item created or a success message, tec.

Now, I think that to have the first action with POST is a problem, because we can’t start the form with a link. Using GET in Create_Item seems a better option.

And also, we can do the same with 3 actions (using the same action for Create_Item and Display_Item, but with an extra flag for reseting the form, for example:
http://www.example.com/controller/Create_Item/?reset=1

And also we can do the same with just 2 actions, because we can use an if inside Create_Item for checking if the request is GET or POST (so we are combining Display_Item with Store_Item).

And also we can do the same with just 1 action, because we can have an extra flag (in the URL query or in a session) for showing the results instead of the form:
GET http://www.example.com/controller/Create_Item/?reset=1 => shows a new form and redirects to the next URL
GET http://www.example.com/controller/Create_Item/ => shows a form with temp data and errors if exists
POST http://www.example.com/controller/Create_Item/ => save errors in temp, or data in DB (and set a session flag for success) and redirects to above URL or next URL
GET http://www.example.com/controller/Create_Item/ => if $_SESSION[‘success’] show results

Personally I like the idea of having 4 actions, but I don’t have any real advantage over the others options. But I don’t feel secure choosing my design without a real criteria.
Does somebody know the PROS and CONS of each design (if any)?

For example, I see the 4 actions cleaner, but if we want to change how the temp data is saved, we need to change it in 4 places.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:48:23+00:00Added an answer on May 21, 2026 at 11:48 pm

    The pattern is to GET a blank form, modify the contents of the form, then POST that to the server, which then sends a redirect to another page which is a GET, perhaps to a page saying Form submitted successfully.. (Get->)Post->Redirect->Get

    The first action is not really POST. That’s the end result of completing a form and submitting it. The guide is more about what to do after that POST, as if you do not do a redirect, then the user is left on a page saying Form submitted successfully where they could just hit F5 and do another POST. With that redirect however, they’re on that results page via a safe GET which will not result in a double post.

    As for the implementation, you should have each be its own action on the server side. This is inline with the MVC / RESTful implementation.

    • GET /url?action=new -> Call new_form() method to render a new form
    • POST /url?action=create -> Call create_form() method to save and redirect to /url?action=show&id=1234
    • GET /url?action=show&id=1234 -> Call show_form() method to display the result
    • POST /url?action=save&id=1234 -> Call save_form() method to save and redirect

    You could use 3 actions here instead if you wanted to have the 2nd action call save. Most REST/CRUD conventions use the 4, but the choice is yours. The benefits are the same as going the REST/MVC route in the first place.

    See these resources as well:

    • RESTful web services
    • This covers typical conventions for RESTful controllers. It covers rails, but still applies to PHP as well if you’re wanting to go the REST route.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C# member variable initialization; best practice? Is there any benefit to this:
is there any best practice way to replace a part of the default template.
Just checking if there's any best practice when writing a Windows Service. The Service
Is Model-View-ViewModel the best pattern to use in WPF? Are there any downsides?
Possible Duplicate: Array versus List<T>: When to use which? Is there any best practice
Is there any best practice with respect to coding style with respect to explicit
Is there any difference (performance, best-practice, etc...) between putting a condition in the JOIN
Is there any merit (coding style, OOP best practice, etc.) in working with an
In EF projects, Is there any best practice for setting AutomaticMigrationsEnabled ? More declaration:
Is there any Best Practice approach to storing persistent static data for iPhone apps?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.