0

Is it possible to redirect to controller action methods through aspx cs page? how can I redirect from a controller action methods

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
Nayeem Mansoori
  • 821
  • 1
  • 15
  • 41
  • http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction%28v=vs.118%29.aspx – David Nov 06 '14 at 13:34
  • why do you want to do it via the aspx? do it from the controller – Avi Pinto Nov 06 '14 at 13:34
  • You can redirect to any working URL, just do `Response.Redirect("/url/of/controller/action");` – Ben Robinson Nov 06 '14 at 13:34
  • if you want to do something on the aspx when it gets to the user and then redirect to another action - use JS -> window.location=.. – Avi Pinto Nov 06 '14 at 13:36
  • @Ben Robinson i'm using Response.Redirect("/url/of/controller/action"); but i'm got this error "Cannot redirect after HTTP headers have been sent." – Nayeem Mansoori Nov 06 '14 at 13:38
  • @NayeemMansoori: Then redirect before sending the headers. If you're on a non-MVC WebForms page then `Response.Redirect()` is how you redirect the user. – David Nov 06 '14 at 13:39
  • @NayeemMansoori then that is nothing to do with the fact that you are redirecting to a controller action, change the URL you will get the same exception. You are likely doing a Response.Redirect too late, at that point the response has already gone to the browser so you can't then redirect. – Ben Robinson Nov 06 '14 at 13:41
  • Please add some code and a better description of what you're trying to accomplish, and what problem/s you are encountering. – Mike C. Nov 06 '14 at 15:08

1 Answers1

1

Any code sample will be helpful. but based on assumption and other comments in questions.

You have to make sure you are passing the correct URL in Response.Redirect. Navigate to top level and then redirect to the required page may be helpful. Also refer to this url : Why do I get "Cannot redirect after HTTP headers have been sent" when I call Response.Redirect()?

Note: I cant add comment, so posting this as answer.

Community
  • 1
  • 1
Kalyan
  • 307
  • 2
  • 14