Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hey friends, just a short question :
How can I redirect from one controller's action to a different controller's action without having the address bar of the browser changed?

I user RedirectToAction now, but this causes the browser to display the new address. I just want to render the content of a different controller's action. If it matters, I want to pass a couple of (string) values to the other view as well.

Thanks a lot
Posted

This isn't a redirect then, in terms of an HTTP redirect, so it's may not be too surprising to see the behaviour you're looking for is absent. The purpose of a redirect is not to control rendering, it's for the server to tell the requesting client about a temporary (or permanent) move of a resource.

Rather than redirecting from the controller action, why not decide to "redirect" and store it in your ViewBag? You can always RenderAction from the view (and pass those string params).

Cheers.
 
Share this answer
 
Comments
Eduard Keilholz 11-Aug-11 3:11am    
Thanks for your reply!
I've found out that you can render a total different view from a controller like so :
return View("~/controller/action.aspx", viewModel);

In my case this satisfies my needs of rendering a total different view and having the ability to pass data to that view using a model.

My have been a very very very beginner (n00b) question/solution, but you know, anybody's gotta learn some time ;)
 
Share this answer
 
Comments
TheyCallMeMrJames 12-Aug-11 9:12am    
No, that's valid, in the sense that it accomplishes what you're looking for (+5 as I actually haven't attempted to invoke the action like that before). But do be mindful that when you're working around a framework to make something work, that it's usually a good time to spend some thought as to why it doesn't work like that in the first place. In this case, it may very well be that your controllers/actions need a rethink (or it may mean that your solution is the best/easiest route to meet your needs).

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