My modal does not carry

Asked

Viewed 136 times

2

I’m having a problem presenting a successful modal after clicking on a btn.

if ('@ViewBag.Mensagem' != '') {
    $(function () {
        $('#ModalSucesso').modal('toggle');
        $('#ModalSucesso').modal({ backdrop: 'static', keyboard: false });
    });
} else {
    $(function () {
        $('#ModalSucesso').modal('hide');
    });
    }


</script>

And my modal:

<div id="ModalSucesso" class="modal fade success" role="dialog" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <br />
            <br />
            <div class="modal-body" style="text-align: center;">
                <p>@ViewBag.Mensagem</p>
            </div>
            <div class="modal-footer" style="text-align: center;">
                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick=" location.href = '@Url.Action("DocumentoCadastro", "SecretariaExecutiva")' ">Ok </button>
            </div>
        </div>
    </div>
</div>

When entering the console, the following error appears:

Failed to load Resource: the server responded with a status of 403 (Forbidden)

Even, it also appears this error:

Matrix.tables.js:10 Uncaught Typeerror: $(...). Uniform is not a Function At Htmldocument. (Matrix.tables.js:10) at j (jquery.js:3137) At object.fireWith [as resolveWith] (jquery.js:3249) At Function.ready (jquery.js:3455) At Htmldocument. J (jquery.js:3496)

I’ve done almost everything to try to solve this problem, I’m new in javascript and still have enough difficulties.

  • The browser found the feature but is not allowed to access it. You will have to pass some valid login that has access to Documentregistration and Secretariaexecutive

  • So, my user id in the bank is tied to this role, including I am able to run my program normally, it just does not load the modal.

1 answer

0

Using Front-end frameworks such as Bootstrap, you make page creation much easier. Bootstrap has very simple modal components to implement, as you can see in this example, as well as in bootstrap documentation. From there using only HTML code you can display the message you want, including it in the body of Divs modal.

Other option:

If you want to use your code please review the excerpt if ('@ViewBag.Mensagem' != '') to capture the tag message P, may not be being used correctly. as you treat the message @ViewBag.Mensagem as a pure string and not necessarily as the value contained within Message.

To make the condition could capture the text value of the tag P:

var valorDaDiv = $("#MensagemModal").text();
if (valorDaDiv != '') {
//Seu código aqui
}

and in HTML use:

<p id="MensagemModal">@ViewBag.Mensagem</p>

For good practices using consolidated tools in the market generates productivity in its development, for javascript or Jquery is highly widespread!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.