javascript click event does not call action - Asp.net Core

0

I created a modal block to display my View Create. When clicking on btnNew, a javascript event should call my Action Create return a blank view and load inside the modal ... Only modal only is opening. I followed with BP and found that the click event is not calling Action Create with the route I'm going through. Can anyone tell me where I'm going wrong?

 [HttpGet]
        [Authorize(Policy = "CanWritePessoaSituacaoData")]
        [Route("situacoes-gerenciamento/cadastrar-novo")]
        public IActionResult Create()
        {
            return View();
        }

Below is the code for btnNew, the modal block and ref. to the script:

 <a id="btnNovo" class="btn btn-outline btn-default new" data-toggle="modal" href="#myModal"
                   data-original-title="Cadastrar Novo" >
                    <span title="Cadastrar Novo" class="icon wb-plus"></span> Cadastrar Novo
                </a>
                
     

<div id="myModal" class="modal fade" role="dialog" data-backdrop="static" tabindex='-1' aria-labelledby="myModalLabel" aria-hidden="true" style="display:none" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                <h4 class="modal-title" id="myModalLabel">Gerenciar Situações de Pessoas</h4>
            </div>
            <div class="modal-body">
                <div id="modal-content">
                    Carregando...
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    
    <script src="~/js/PessoaSituacao/PessoaSituacao.js"></script>
    <script type="text/javascript">
    
    }

Follow the js script:

$("btnNovo").click(function (eve) {
    $("#modal-content").load("situacoes-gerenciamento/cadastrar-novo");
});
    
asked by anonymous 07.05.2018 / 16:46

1 answer

0

The problem is in your pointing in the button click event

$("btnNovo").click(function (eve) {
    $("#modal-content").load("situacoes-gerenciamento/cadastrar-novo");
});

Here you are only indicating the route of your action from the current route which includes the current action. As reported in the comments its Controller is called PessoaSituacaoController and does not have a route customization for it, so by default it would be PessoaSituacao . Taking these notes into account, in order to solve your problem, you just have to indicate the url for loading the modal, respecting the pattern /{Controller}/{Action ou Rota}/ , which in your case would look like this:

$("btnNovo").click(function (eve) {
    $("#modal-content").load("/pessoaSituacao/situacoes-gerenciamento/cadastrar-novo");
});
    
09.05.2018 / 16:12