Response.redirect is not redirecting in c#

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);
    }

Answers


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);
    }
});

Need Your Help

Create CSV from specific columns in another CSV using shell scripting

bash shell csv

I have a CSV file with several thousand lines, and I need to take some of the columns in that file to create another CSV file to use for import to a database.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.