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>