I am doing a delete with Ajax and returning a JSon. How do I open a different view? Here is the code, I put the url but it does not work:
View
$.ajax({
url: '@Url.Action("ExcluirPedidoCompra")', // to get the right path to controller from TableRoutes of Asp.Net MVC
dataType: "json", //to work with json format
type: "POST", //to do a post request
contentType: 'application/json; charset=utf-8', //define a contentType of your request
cache: false, //avoid caching results
data: "{\"id\" : " + id + "}", // here you can pass arguments to your request if you need
success: function (data) {
if (data > 0) {
url: '/PedidoCompraConsultar/Index'
}
},
error: function (xhr) {
alert("Erro! Ocorreu um erro ao excluir, Favor Entrar em Contato com O Suporte.");
}
});
controller code
public ActionResult ExcluirPedidoCompra(int id)
{
var resultado = 1;
return Json(resultado);
}
I've tested it all the way. If anyone can help me I want to go to "RequestCompraConsultController - Index".