I have a MVC application with Jquery; I have a gridview with some data and an element which points to a new action of the controller.
Now I need to do some validation before executing the action.
My code is like this:
$('#datosCartolaSeguro a').click(function(e) {
var datosProductoSeleccionado = $(this).parent().find('input').val();
$.post(pathSite + 'PorSegurosCartola/ProductoTieneCartola',
{
strDatosProducto: datosProductoSeleccionado
},
function(resp) {
if (resp == 'False') {
popupActual = '#popupProdNoTieneCartola';
centrarPopup();
cargarPopup();
}
else {
mostrarVentanaAdvertencia();
return true;
}
}
);
});
After the call to the method: cargarPopup() I want to avoid the execution of the click of the action link. I tried with a simple return false, but the the page does a postback. I also tried with the function e.preventDefault(); that was posted in other solution on this forum, but it doesnt works. I need to avoid the clicking of the ActionLink but with no postback.
Thanks.
You need to stop the even from happening while you are waiting for the response to the post so you should be adding the return false; or e.preventDefault() after the post call.