Click here to Skip to main content
13,045,180 members (40,023 online)
Rate this:
Please Sign up or sign in to 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 10-Aug-11 0:55am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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).

Eduard Keilholz 11-Aug-11 3:11am
Thanks for your reply!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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 ;)
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 11 Aug 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100