Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have autogenerated MVC set; and in this particular case, I'm utilizing only the Details and Edit view pages, as the id is determined elsewhere and create, delete, and index are all not applicable. Consequently, I have a different controller directly invoking the Details page with the id and from the Details page you can go to the Edit page as normal. That's unchanged.

My problem is when the user clicks Save on the Edit page, it follows its usual pattern of routing to the Controller name, which defaults to returning back to the Index page. I, of course, want it to return to the Details page (after successfully saving the changes), and ignore the Index page completely.

There are no parameters in the Html.Beginform() on the Edit page and nothing else that I can see that predetermines that it will jump back to the Index page after clicking Save.

How can I get it to return to the Details page after clicking Save on the Edit page?

Thank you in advance for any help you can afford me.

What I have tried:

I tried a redirect from the Index controller action but it just goes to a blank page.

public void Index()
{
RedirectResult rr = RedirectPermanent(@"myController\Details\" + ViewBag.Client_ID);
}

I have also tried adding the controller, action, and id parameters in the otherwise parameterless Html.Beginform() directive in the Edit page; but although it does redirect to the Details page as desired, the edits from the Edit page fail to save.
Posted
Updated 7-Nov-16 20:19pm

1 solution

Hello,

If you are posting the form and saving, then after successfully saving, return the user to the Details page using the RedirectToAction method.
Controller.RedirectToAction Method (System.Web.Mvc)[^]
This will redirect the user and land the user to the desired page.

Thanks
 
Share this answer
 
Comments
Member 12824529 13-Nov-16 19:19pm    
Thanks. Yes, I put this in the Index ActionResult and it works:

return RedirectToAction("Details", new { id = Convert.ToInt32(Session["Assmt_ID"].ToString()) });

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900