Response.redirect is not redirecting in c#
asp.net-mvc, c#
Solution
You cannot do a redirect on an ajax post, that will give you a 302 error. What you should be doing is to return the url from you controller method
public ActionResult Redirect()
{
return Json(the_url);
}
and then redirect from your client-code:
$.ajax({
// your config goes here
success: function(result) {
window.location.replace(result);
}
});
Problem
I want to redirect to certain website using c#. I have written the code like: HTML: ``` <button id="Buy" class="k-button">Button</button> ``` Script: ``` $("#Buy").live('click', function () { $.ajax({ url: "/Home/Redirect", data: JSON.stringify ({ }), cache: false, dataType: "json", success: function (str) { }, type: 'POST', contentType: 'application/json; charset=utf-8' }); }); ``` c#: ``` public ActionResult Redirect() { Response.Redirect("http://www.google.com"); return Json("suc",JsonRequestBehavior.AllowGet); } ```