8
I have a button on my screen that held call to a method on my controller (Ajax) that returns a partialView by default.
$("#btn-Visualizar-Rotina").click(function() {
var codUnimetPcp = '@Model.UnidadeMetalica.COD_UNIMET_PCP';
$("#modal-Rotina").load("Rotina/Index", { "codUnimetPCP": codUnimetPcp }, function (result) {
$("#modal-Rotina").modal({
backdrop: 'static',
keyboard: true
}, 'show');
});
});
However, in my control, I need to validate again if the user really has permission in the method in question, and in the negative case derive to a standard security page. In the validation function, when the user does not have access, I have the following code snippet
filterContext.Result = new ViewResult
{
ViewName = "~/Views/AcessoNegado.cshtml",
ViewData = filterContext.Controller.ViewData,
TempData = filterContext.Controller.TempData,
};
However, when this situation occurs, my page AcessoNegado.cshtml
is not being loaded. It is being rendered inside the modal.
I tried to return a Viewbag indicating that the authentication failed to display the modal, but it always comes null
.
I would like your help in solving this problem in the best way possible.
There is a problem in its formulation. Depending on the result of Ajax, the screen requires a state transfer. That is, your Ajax should not return a
ViewResult
. You need to decide whether logic has to transfer the state of the screen or not. If it is not, the correct thing is to display a JS message explaining the lack of access.– Leonel Sanches da Silva
In fact, redirecting to a new page is a definition of the application scope... Not being Viewresult, do you have any idea what I can return? Or it is necessary to make a change in the form in which the controller is being called and consequently the Modal?
– Carlos Henrique Biazin Esteves
For functions that do not return partialView and are not opened in modal, the redirect works correctly.
– Carlos Henrique Biazin Esteves
From what I understand, the result of the modal should be a JSON containing some business rule code. If there is no permission, the JS must transfer the screen to the unauthorized screen.
– Leonel Sanches da Silva
I was trying to return some indication after the call Ajax so that the event "load" modal was not executed, preventing the page "without permission" was opened inside the modal
– Carlos Henrique Biazin Esteves
I was thinking of a way that when the controller redirects, the event that opens the modal would not be executed...
– Carlos Henrique Biazin Esteves