4

I'm trying to redirect a user from a method on a controller to another view but can't get it to work no matter what I do. What am I doing wrong? Here's my code:

            public ActionResult SubmitReport(string JsonStringSend)
        {
            dynamic JSend = JObject.Parse(JsonStringSend);
            var schema = JsonSchema4.FromType<ReportItem>();
            var schemaData = schema.ToJson();
            var errors = schema.Validate(JSend.JsonString);
            schema = JsonSchema4.FromJson(schemaData);


            //Check for errors and show them if they exist
            if (errors.Count > 0)
            {
                //JSchema schema = JSchema.Parse(schema);
                foreach (var error in errors)
                    Console.WriteLine(error.Path + ": " + error.Kind);

                //JObject JsonString = JObject.Parse(JsonObj.JsonString.ToString());
                //JObject JsonStringSent = JObject.Parse(JsonStringSend);

            }
            else
            {
                return Redirect("/Admin/Reporting/ReportManagement");
            }
            return View();
        }

It never redirects. I've even tried these:

Response.Redirect(Url.Action("/ReportManagement"));
RedirectToRoute(new { contoller = "ReportManagement", action = "Reporting" });
return RedirectToRoute(new { contoller = "Reporting", action = "ReportManagement" });
return RedirectToAction("ReportManagement");

Nothing seems to redirect, what gives?

9
  • If you step through the code in debug mode, what happens? Commented May 6, 2016 at 20:26
  • Nothing, when I get to return Redirect("/Admin/Reporting/ReportManagement"); it just keeps on stepping Commented May 6, 2016 at 20:37
  • What's your current URL? Commented May 6, 2016 at 20:46
  • plus.inroll.com/Admin/Reporting/EditReport Commented May 6, 2016 at 20:46
  • the return RedirectToAction("Whatever") should respond to your browser with a 302 response and make the browser request the "Whatever" URL. That's really strange. You could probably fire up Fiddler and see what response is coming back, if any. Commented May 6, 2016 at 20:50

2 Answers 2

16

You don't redirect to a view, you redirect to an action or a route. If I'm correctly parsing the path you're attempting, where you have this:

return Redirect("/Admin/Reporting/ReportManagement")

should be

return RedirectToAction("Reporting", "ReportManagement", new { area="Admin" }) 

This assumes a Reporting action on a ReportManagementController class in the Admin area.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for showing the route value params for "Areas." Big help!
4

Try this, it should be work:

return RedirectToAction("yourAnotherActionName","yourAnotherControllerName"); //It's very simply;)

I've tested it!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.