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

  • SEARCH
  • Home
  • 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 7946695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:13:28+00:00 2026-06-04T01:13:28+00:00

I have a controller with an Index method that has several optional parameters for

  • 0

I have a controller with an Index method that has several optional parameters for filtering results that are returned to the view.

public ActionResult Index(string searchString, string location, string status) {
    ...

product = repository.GetProducts(string searchString, string location, string status);

return View(product);
}

I would like to implement the PRG Pattern like below but I’m not sure how to go about it.

[HttpPost]
public ActionResult Index(ViewModel model) {
    ...
    if (ModelState.IsValid) {
        product = repository.GetProducts(model);
    return RedirectToAction(); // Not sure how to handle the redirect
    }
return View(model);
}

My understanding is that you should not use this pattern if:

  • You do not need to use this pattern unless you have actually stored some data (I’m not)
  • You would not use this pattern to avoid the “Are you sure you want to resubmit” message from IE when refreshing the page (guilty)

Should I be trying to use this pattern? If so, how would I go about this?

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-06-04T01:13:29+00:00Added an answer on June 4, 2026 at 1:13 am

    PRG Stands for Post-Redirect-Get. that means when you post some data to the server back, you should redirect to a GET Action.

    Why do we need to do this ?

    Imagine you have Form where you enter the customer registration information and clicking on submit where it posts to an HttpPost action method. You are reading the data from the Form and Saving it to a database and you are not doing the redirect. Instead you are staying on the same page. Now if you refresh your browser ( just press F5 button) The browser will again do a similar form posting and your HttpPost Action method will again do the same thing. ie; It will save the same form data again. This is a problem. To avoid this problem, We use PRG pattern.

    In PRG, You click on submit and The HttpPost Action method will save your data (or whatever it has to do) and Then do a Redirect to a Get Request. So the browser will send a Get Request to that Action

    RedirectToAction method returns an HTTP 302 response to the browser, which causes the browser to make a GET request to the specified action.

    [HttpPost]
    public ActionResult SaveCustemer(string name,string age)
    {
       //Save the customer here
      return RedirectToAction("CustomerList");
    
    }
    

    The above code will save data and the redirect to the Customer List action method. So your browser url will be now http://yourdomain/yourcontroller/CustomerList. Now if you refresh the browser. IT will not save the duplicate data. it will simply load the CustomerList page.

    In your search Action method, You dont need to do a Redirect to a Get Action. You have the search results in the products variable. Just Pass that to the required view to show the results. You dont need to worry about duplicate form posting . So you are good with that.

    [HttpPost]
    public ActionResult Index(ViewModel model) {
    
        if (ModelState.IsValid) {
            var products = repository.GetProducts(model);
            return View(products)
        }
      return View(model);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP MVC3 application that has several HttpPost ActionResult methods. During a
I have a simple controller called list_controller with an index that basically does def
I have a controller named Content, which has an Index action, which is associated
I have an app that has a UINavigationController that pushes a UITabBarController into view.
I have one area Area1 with controller Home and it's Index method. I also
I have a _layout page which has a login box (partial view) and that
In my controller I have: @invoices = current_user.account.clients.map(&:invoices).flatten and in my index.html.erb I want
I have controller PlayerController and actions inside: View , Info , List . So
I have Controller: [MySite]\Controllers\DistributionTools\TrackingChannelsController.cs [HttpPost] public void InitTcFirstPageView() { var model = new TcFirstPageModel
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;

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.