0
Inside the controller of my partial View that are opened in modal I make a validation if the token is valid, in case everything happens well it will open and show the content, and this happens normal, but if the token is expired I programmed it to be redirected to the method of undoing, then the user would be undocked and would have to log in again, what happens and that the modal loads the login page and updating the page it does the process that should be done.
follows the controller:
[HttpGet]
public async Task<IActionResult> Partial_Visualizar(int id)
{
try
{
if (!SessaoExpirada)
{
var receita = await _receitaService.VisualizarReceitaId(id, Token);
if (receita == null)
{
return Json("Erro ao carregar receita!!");
}
var receitaMap = _mapper.Map<ReceitaModel>(receita);
return View(receitaMap);
}
return RedirectToAction("Deslogar", "LoginUsuario", new { msg = "Sessao expirada refaça o login" });
}
catch (Exception)
{
return Json("Erro no servidor!");
}
}
follows the scribe who opens the modals:
ShowInModal = (url, title, id) => {
$.ajax({
type: "GET",
url: url,
success: function (res) {
$("#exampleModal .modal-body").html(res);
$("#exampleModal .modal-title").html(title);
$("#exampleModal").modal('show');
}
});
};
follows . csthml the part that makes the call of modals:
@foreach (var modelo in Model)
{
<tbody>
<tr class="table-light">
<th scope="row">@modelo.Id</th>
<td>@modelo.Titulo</td>
<td>@modelo.Data_Publicacao</td>
<td>
<div class="btn-group" role="group" aria-label="Exemplo básico">
<a onclick="ShowInModal('@Url.Action("Partial_Visualizar","Perfil",new {id = modelo.Id},Context.Request.Scheme)','Visualizar Receita')"
class="visualizar btn btn-info btn-sm">Visualizar</a>
<a onclick="ShowInModal('@Url.Action("Partial_Editar","Perfil",new {id = modelo.Id},Context.Request.Scheme)','Editar Receita')"
class="editar btn btn-warning btn-sm">Alterar</a>
<a onclick="ShowInModal('@Url.Action("Partial_Delete","Perfil",new {id = modelo.Id},Context.Request.Scheme)',null)"
class="deletar btn btn-danger btn-sm">Deletar</a>
</div>
</td>
</tr>
</tbody>
}
Error image that appears on the Chrome console:
My doubt is why this redirection is not done and why the login page is open within the modal, what I would have to change for my idea to work?
Thank you for the reply! I had already solved this but in an ugly way creating a button in the same controller and made a function to update the page. But your answer didn’t work exactly, but doing some research added an error below so Success:
error: function () {
 var msg = 'Sessao expirada refaça o login';
 window.location.href =
/Loginusuario/Deslogar? msg=${msg};
 }
and kept the unathorized you pointed out and now it’s running good vlw man!!– rbt