I am new to MVC and am accustomed to web forms and the events of the controls that cause the postback and refresh the page.
I need to make this update on the MVC page after a javascript is triggered.
In the code below I was able to call the method I need but it does not do the postback (reflesh) of the page automatically, neither using $ post nor using $ ajax
To update the page I'm using location.reload (); which only does the postback (reflesh) only at the end of running $ post or $ ajax.
I need an "effect" just like an "asp: button" that onClick already flashes the screen on time and runs the C # code on the server.
Well I hope I have been able to get the right information I need.
<script type="text/javascript">
var totalPaginas = parseInt('@ViewBag.TotalPaginas');
var paginaAtual = parseInt('@ViewBag.PaginaAtual');
var registrosPorPagina = parseInt('@ViewBag.RegistrosPorPagina');
$('#divPaginacaoUm').bootpag({
total: totalPaginas,
page: paginaAtual,
maxVisible: registrosPorPagina,
leaps: true,
firstLastUse: true,
first: '<',
last: '>',
wrapClass: 'pagination',
activeClass: 'active',
disabledClass: 'disabled',
nextClass: 'next',
prevClass: 'prev',
lastClass: 'last',
firstClass: 'first'
}).on("page", function (event, num) {
$.ajax({
type: 'POST',
url: '@Url.Action("Paginacao", "Pesquisa")',
data: { 'num': num },
dataType: 'html',
cache: false,
async: true,
success: function (data) {
location.reload();
}
});
$.post('@Url.Action("Paginacao", "Pesquisa")', { num: num }, function (data) {
location.reload();
});
});