0
I am doing an error handling using Json Result, when displaying the error message I should display the page formed as it rules in the _Layout file, so the page is loading all blank, does anyone know how to resolve? Below the image of how it is being displayed!
Here is my homeController:
using ReportandoErro.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace ReportandoErro.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Teste()
{
var response = new ResponseViewModel();
try
{
throw new Exception("Oops, ocorreu um erro");
}
catch (Exception e)
{
return ErroCapturado(e);
}
return Json(response, JsonRequestBehavior.AllowGet);
}
public ActionResult ErroCapturado(Exception ex)
{
var response = new ResponseViewModel
{
Data = ex.Data,
Sucesso = false,
Mensagem = ex.Message
};
return Json(response, JsonRequestBehavior.AllowGet);
}
}
}
Here my Accountviewmodels:
public class ResponseViewModel
{
public object Data { get; set; }
public bool Sucesso { get; set; }
public string Mensagem { get; set; }
}
And here the view called test:
@{
ViewBag.Title = "Teste";
}
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@model ReportandoErro.Models.ResponseViewModel
<h2>Teste</h2>
<script type="text/javascript">
$(document).ready(function () {
//debugger;
gerandoRelatorio();
function gerandoRelatorio() {
$.getJSON("Home/Teste", function (response) {
if (response.sucesso) {
console.log(response.data);
}
else {
alert(data.mensagem);
}
}).fail(function (response) {
//Erro genérico
alert("Não foi possível processar a sua requisição");
});
}
});
</script>
So Leonardo, I did it here, so it’s returning the test view, but it’s not displaying the error log, how to make this error log displayed in this view?
– WPfan
And I noticed something else, he’s not getting into that Ajax_test
– WPfan
@Wpfan take a look
– Leonardo Bonetti
@Wpfan which framework you are using to perform the request?
– Leonardo Bonetti
am using Asp.net mvc
– WPfan
@Wpfan updates your Javascript, see if this way will
– Leonardo Bonetti
Still continues the same way, I’m almost punching the notebook kkkkkk
– WPfan
You need to debug, know if you’re coming to the Ajax_test action, then, if you’re coming, know if you’re returning something. do this test and tell me how well it’s working
– Leonardo Bonetti
he’s not getting into Ajax_test, that’s the problem!!
– WPfan
Let’s go continue this discussion in chat.
– WPfan