Call Index action after a POST with MVC

I had a page with a list of records that the user could view to see what was in the queue of things to do. The user would click on the link to bring up a table where they could choose which record to edit.

Choosing this record would populate the view with the fields. The user could then update the values, click “Save” to generate a POST request, and then return back to the Index view.

The problem was that my redirect to the Index view, while returning to the right view, wasn’t showing the link with the remaining records. Here is how I was attempting to do this:

return View("Index", item);

To fix this, I made a call to “RedirectToAction” to call the controller’s Index action:

return RedirectToAction("Index", "MyController", item);

The fields were cleared just as I wanted (because I had set the model to null before passing into “RedirectToAction”) and the remaining records link was there as expected.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: