Galera, it's the following, in my application I would like a page to appear with the error occurred, but this page has all the formatting proposed in the layout, so this is not happening because it only generates a blank page with the error code. Here are the code I'm using:
In the homeController:
public ActionResult ExemploErroNaoMapeado()
{
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);
}
In manageViewModels I've added:
public class ResponseViewModel
{
public object Data { get; set; }
public bool Sucesso { get; set; }
public string Mensagem { get; set; }
}
And the page that should display the error looks like this:
<h2>
Ocorreu um erro não mapeado durante a execução
da última ação...
</h2>
<script type="text/javascript">
$(document).ready(function () {
//debugger;
gerandoRelatorio();
function gerandoRelatorio() {
$.getJSON("Home/ExemploErroNaoMapeado", 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 I want to know how to make the layout work on this page, since it loads all white and does not even bring the menu together?
With the changes suggested by the friend below, this error appears: