1
I am new to MVC and am used to web Forms and the events of the controls that cause postback and update the page.
I need to do this update on the MVC page after a javascript is triggered.
In the code below I managed to call the method I need but it does not postback (reflesh) the page automatically, either using $post or using $ajax
To update the page I am using Location.Reload(); which only does postBack(reflesh) at the end of $post or $ajax execution.
I need an "effect" equal to an "Asp:button" that onClick already flashes the screen on time and executes on the server the code c#.
Well I hope I got the right information out of what 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();
});
});
I think that in the MVC architecture you should call the controler, sending the viewmodel, the controler will do what has q be done with the viewmodel and return the view (which may be the same) with a new viewmodel, this view can be worked with this new object, gave to understand?
– Ricardo
I could understand what you meant, but I don’t know how to do it.
– Mauricio Ferraz