Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET MVC
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
good
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).
 
Cheers.
  Permalink  
Comments
Eduard Keilholz at 11-Aug-11 3:11am
   
Thanks for your reply!
Rate this: bad
good
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 Wink | ;)
  Permalink  
Comments
TheyCallMeMrJames at 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
0 George Jonsson 359
1 Sergey Alexandrovich Kryukov 355
2 CPallini 335
3 BillWoodruff 324
4 OriginalGriff 237
0 OriginalGriff 5,050
1 CPallini 4,225
2 Sergey Alexandrovich Kryukov 3,639
3 George Jonsson 2,911
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 11 Aug 2011
Copyright © CodeProject, 1999-2014
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