0
Hello I generated some error pages in my application in mvc, however I realized that this giving error when I try to load a modal, instead of it load my modal it loads the page of error 404 follow my codes
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Response.Clear();
HttpException httpException = exception as HttpException;
int error = httpException != null ? httpException.GetHttpCode() : 0;
Server.ClearError();
Response.Redirect(String.Format("~/Error/?error={0}", error, exception.Message));
}
error controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using macpartner.Models;
namespace macpartner.Controllers
{
public class ErrorController : Controller
{
private MacPartnerContext db = new MacPartnerContext();
// GET: Error
public ActionResult Index(int error = 0)
{
switch (error)
{
case 500:
ViewBag.Imagem = "https://i.imgur.com/JUtjbnQ.png";
break;
case 404:
ViewBag.Imagem = "https://i.imgur.com/6hW4WwF.png";
break;
default:
ViewBag.Imagem = "https://i.imgur.com/nBbSpyD.png";
break;
}
return View("~/views/error/_ErrorPage.cshtml");
}
}
}
page with modal:
@model IEnumerable<macpartner.Models.LeadCashBack>
@{
ViewBag.Title = "Meus Bônus";
}
@section Scripts{
<script>
$(function () {
$("#PontosDisponiveis").click(function () {
var id = $(this).attr("data-id");
$("#modalBonusDisponiveis").load("Details?id=" + id, function () {
$("#modalBonusDisponiveis").modal();
})
});
</script>
<script type="text/javascript">
$("#BtnResgataValor").click(function () {
if ($('#hasContaBancaria').text() == "True") {
location.href = '@Url.Action("ResgataBonusAsync", "LeadCashBacks")';
swal({
title: "Pronto!",
text: "Solicitação confirmada, agora é só esperar o pessoal da Manchester depositar a grana pra você ;)",
icon: "success",
button: "Entendi!",
});
}
else {
swal({
title: "Ops!",
text: "Antes de solicitar o resgate dos seus bonus é necessário cadastrar seus dados bancários. Tô te direcionando...",
icon: "warning",
});
setTimeout(
function () {
location.href = '@Url.Action("Create", "UserDadosBancarios")';
}, 7000);
}
});
</script>
}
@{
Layout = "~/Views/Shared/_Layout.cshtml";
decimal TotalValor = 0;
decimal ValoresDisponiveis = 0;
decimal ValoresUtilizados = 0;
var hasContaBancaria = false;
macpartner.Models.MacPartnerContext db = new macpartner.Models.MacPartnerContext();
macpartner.Models.User user = new macpartner.Models.User();
user = db.Users.Where(u => u.UserName == User.Identity.Name).First();
var userDadosBancarios = db.UserDadosBancarios.Where(u => u.UserId == user.UserId).ToList();
if (userDadosBancarios.Count > 0)
{
hasContaBancaria = true;
}
else
{
hasContaBancaria = false;
}
foreach (var item in Model)
{
if (!item.Contemplado)
{
ValoresDisponiveis += item.ValorProdutos + item.ValorServicos;
}
else
{
ValoresUtilizados += item.ValorProdutos + item.ValorServicos;
}
TotalValor += item.ValorProdutos + item.ValorServicos;
}
}
<div class="jumbotron">
<img class="banner_full" src="https://i.imgur.com/0acNo2Y.png" />
<img class="banner_reduzido" src="~/Content/Resources/bonus_reduzido.png" />
</div>
<div class="MyContent" style="margin-top:-40px">
<h4>Resumo de Bonus</h4>
<center>
<div class="MyHeaderContent">
<table class="table-bordered">
<thead>
</thead>
<tbody>
<tr>
<td>
<div class="MyDashboardDiv" id="PontosDisponiveis">
<center><h4>Bônus Disponíveis</h4></center>
<center><h3 class="count">@ValoresDisponiveis</h3></center>
</div>
</td>
<td>
<div class="modal fade" id="modalBonusDisponiveis">
<p id="hasContaBancaria" hidden>@hasContaBancaria</p>
<div class="modal-dialog" style="width:60%">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Fechar</span></button>
<h4 class="modal-title">Bônus Disponíveis</h4>
</div>
<div class="modal-body">
<h4>Extrato de Bônus Disponíveis</h4>
<div>
<table class="table">
<thead>
<tr>
<th class="MyTh">
<h5>Nome Fantasia</h5>
</th>
<th class="MyTh">
<h5>Documento</h5>
</th>
<th class="MyTh">
<h5>Total Produtos</h5>
</th>
<th class="MyTh">
<h5>Total Serviços</h5>
</th>
<th class="MyTh">
<h5>CashBack Produtos</h5>
</th>
<th class="MyTh">
<h5>CashBack Servicos</h5>
</th>
</tr>
</thead>
@foreach (var item in Model)
{
macpartner.Models.Lead lead = macpartner.Helpers.LeadHelper.LeadPontosById(item.LeadId);
if (!item.Contemplado)
{
<tbody>
<tr>
<td class="MyTrTd">
<h5>@lead.fantasia</h5>
</td>
<td class="MyTrTd">
<h5>@lead.cnpj_cpf</h5>
</td>
<td class="MyTrTd">
<h5>R$ @lead.ValorProdutos</h5>
</td>
<td class="MyTrTd">
<h5>R$ @lead.ValorServicos</h5>
</td>
<td class="MyTrTd">
<h5>R$ @item.ValorProdutos</h5>
</td>
<td class="MyTrTd">
<h5>@item.ValorServicos</h5>
</td>
</tr>
</tbody>
}
}
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" data-dismiss="modal">Fechar</button>
@if (ValoresDisponiveis > 0)
{
<button type="button" class="has-load btn btn-success" id="BtnResgataValor">Resgatar Valor</button>
}
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
modal controller
[Authorize(Roles = "Admin, Parceiro")]
public async Task<ActionResult> ResgataBonusAsync()
{
user = db.Users.Where(u => u.UserName == User.Identity.Name).First();
var userDadosBancarios = db.UserDadosBancarios.Where(u => u.UserId == user.UserId).ToList();
if (userDadosBancarios.Count > 0)
{
var db2 = new MacPartnerContext();
var leadsCashBack = db2.LeadCashBacks.Where(l => l.Contemplado == false && l.UserId == user.UserId);
decimal totalCashBack = 0;
foreach (var item in leadsCashBack)
{
totalCashBack += (item.ValorProdutos + item.ValorServicos);
}
//Configura objeto de lote
var lote = SeparaLote(leadsCashBack);
lote.UserId = user.UserId;
await LeadHelper.AddLeadCashBackLoteAsync(leadsCashBack, lote);
var loteId = LeadHelper.loteId;
//altera status do lote
db2.Database.ExecuteSqlCommand("UPDATE dbo.LeadCashBacks SET Contemplado = '1' WHERE UserId = " + user.UserId);
await db2.SaveChangesAsync();
//Configurações e-mail de resgate de bonus
var parceiro = user.FirstName + " " + user.LastName + " (" + user.UserName + ")";
var callbackUrl = Url.Action("Edit/"+loteId, "LeadCashBackLotes", null, protocol: Request.Url.Scheme);
user = db.Users.Where(u => u.UserId == user.UserId).FirstOrDefault();
var body = macpartner.Resources.solicitacaoDeResgateBody;
body = body.Replace("[financeiro]", "Cida");
body = body.Replace("[parceiro]", parceiro);
body = body.Replace("[total]", totalCashBack.ToString());
body = body.Replace("[banco]", userDadosBancarios[0].Banco);
body = body.Replace("[agencia]", userDadosBancarios[0].Agencia);
body = body.Replace("[conta]", userDadosBancarios[0].Conta);
body = body.Replace("[tipo]", userDadosBancarios[0].Tipo);
body = body.Replace("[nome-favorecido]", userDadosBancarios[0].Nome);
body = body.Replace("[documento-favorecido]", userDadosBancarios[0].Documento);
body = body.Replace("[celular-favorecido]", userDadosBancarios[0].Celular);
body = body.Replace("[link]", callbackUrl);
var userFinanceiro = db.Users.Where(u => u.Financeiro).FirstOrDefault();
await MailHelper.SendMail(userFinanceiro.UserName, "IndicaMais - Solicitação de Resgate de Bonus", body);
}
else
{
return RedirectToAction("Create", "UserDadosBancarios");
}
return RedirectToAction("Index");
}
Maybe because the path is actually wrong... you’ve checked the url you’re trying to access when you try to do the
load('Details?id=...'
– Leandro Angelo
So when I leave disabled the error 404 it loads the page, only when it is enabled
– Wesley Henrique
tries to reduce a little the code of your question, present only what is relevant to the diagnosis and reproduction of the problem, a [MCVE]. The way it is it gets a little confusing to understand.
– Leandro Angelo
I only let the modal that has to load, but this web page uses 3 modal
– Wesley Henrique
Where is the Details Action, debugging, when it enters the error controller?
– Leandro Angelo
In case Details is not in the controler, it loads the java script
– Wesley Henrique
But you need to answer that route, no?
– Leandro Angelo
The page pulls the id of the java script, it does not have a view page created in the views, it is to load the index
– Wesley Henrique
I understood what you meant, I made the custom error, another programmer made the modal, I will need to create a view to be treated in error 404, before the custom it works for this reason
– Wesley Henrique