I like Serlok's method. I use a similar approach on projects quite often. I don't use it to redirect pages, but I send responses back often for various alerts. I just prefer since I've already sent the request to the server, why send a response back to the calling ajax method? Just redirect to another view right there.
This way is just a different alternative. You use the controller to RedirectYourAction. Another controller, which will fire your view. This way has worked well for me
var data = JSON.stringify({ 'number': userInput});
$.ajax({
method: "POST",
url: '/controller/CheckNumber',
contentType: 'application/json',
data: data,
success: function(response){
console.log(response);
//You could do your redirect here.
}
}
})
public ActionResult CheckNumber(string number)
{
int List = Convert.ToInt32(number);
if (List != 0) //You have List here, you sure you don't mean number? Or you're instantiating a list somewhere..
{
RedirectToAction("Index"); //Takes you to your index controller and the view associated with it. Same as below.
}
else
{
RedirectToAction("SomeOtherControllerName");
}
return View();//default controller view.
}