0

I'm unable to redirect to my Get method after the Post method in the same controller as shown below..

My javascript code which initiates Post call..

$.ajax("home/myquery", {
    /*data: JSON.stringify(tmp1),*/
    data:  JSON.stringify({id:tmp1}),
    type: "post", contentType: "application/json",
    success: function (result) { window.location.replace(window.location.host + '/MyController/MyReport/'+ result); },
    error: function (result) { alert("Error Saving") }
    });

My method in asp.net mvc controller which accesses the call..

[HttpPost]
public ActionResult MyQuery(string id)
{  
//do some work here

    return return this.Content("abc");
}

The method to which it needs to redirect..

[HttpGet]
        public ActionResult MyReport(string model)
        {
            return View();
        }

Any help is sincerely appreciated.

Thanks

4
  • 1
    you can't redirect this way in ajax call return url as json and redirect from js in sucess function Commented Mar 26, 2015 at 9:43
  • @EhsanSajjad - ok have changed the code, still not working Commented Mar 26, 2015 at 10:29
  • window.location.href = '@Url.Action("MyReport","MyController")?model='+ result; Commented Mar 26, 2015 at 11:17
  • If you intending to redirect if successful, then your should be using a standard submit, not ajax (and if there is an error, return the view) Commented Mar 26, 2015 at 23:23

1 Answer 1

1

Since you're setting the expected return of "application/json", you should return from your controller this: return JSON("abc")

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

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.