AJAX success return incorrect

0

I'm using Jquery AJAX in my ASP.NET MVC application and I'm having a rather strange problem. When performing an AJAX request, instead of being retuned the content I want to load (a new ".cshtml" page) is returned the same content as the current page. I searched the console for some error, and debugged using dev tools, but I still do not understand what's wrong.

HTML button:

<button class="btn btn-primary-outline button-custom" id="NovoCodigo">
    <span class="glyphicon glyphicon-plus" style="color:#808080;">
    </span>
    <h4 style="display:inline; color:#808080;">Novo código</h4>
</button>

Jquery onClick:

$('#NovoCodigo').on('click', function () {
    var get_url = this.id;
    get_url = 'codigosCaixa/' + get_url + '.cshtml';
    $.ajax({
        url: get_url,
        success: function (data) {
            $('#content-load').html(data);
            },
            beforeSend: function () {
                $('#loader').css({display: "table"});
            },
            complete: function () {
                $('#loader').css({display: "none"});
            }
        });

Folder Structure



DisplayedpagePS:ThehighlightinyellowisthepressedbuttonthatcallstheAJAX.Noticethatthesamecontentofthepageisrenderingwheretheviewshouldappear"boxCodes / NewCode.html"

EDIT:

ViewCodeNewCode.cshtml:

<divclass="col-md-12">
<h4 style="margin-top:50px; margin-bottom:20px;">Cadastrar código</h4>
<form action="@Url.Action("Create","CodigosCaixa")" id="form-manual" method="post" class="form-horizontal">
    //Campos do form
           .
           .
           .
    </form>
</div>
    
asked by anonymous 30.11.2017 / 14:11

1 answer

1

If you want to keep the HomeController and the view is

    [HttpGet()]
    public ActionResult NovoCodigo() {

        //Adicionar a lógica necessária para rederizar sua View            

        return View("~/Views/Home/codigosCaixa/NovoCodigo.cshtml"); 
        //Adicionar uma model caso seja necessáiro.
    }

And the request you make to:

$('#NovoCodigo').on('click', function () {
var get_url = this.id;
get_url = '/Home/NovoCodigo';
$.ajax({
    url: get_url,
    success: function (data) {
        $('#content-load').html(data);
        },
        beforeSend: function () {
            $('#loader').css({display: "table"});
        },
        complete: function () {
            $('#loader').css({display: "none"});
        }
    });
    
30.11.2017 / 19:58