I'm trying to display a dialog before sending the ajax request, but I'm not getting the correct response depending of the clicked button. but I only get two results or the dialog is displayed but the request is sent or it never sends a request.
I don't want to use pure jQuery due to my strong typed view and my controller action which expects a model, so I think this will be another very big problem I'll need to resolve.
this is my layout
Checador@RenderSection("cs", required: false)
SOME TITLE BLAH BLAH |
@using ( Html.BeginForm("LogOff", "Login", FormMethod.Post, new { id = "logoutForm" }) ) { @Html.AntiForgeryToken() Cerrar Sesion } |
@RenderBody() | |
Abarrotes Monterrey © 2014 Mexico(Es) |
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@RenderSection("scripts", required: false)
function desaparece(data, textStatus, jqXHR) {
$("#MensajeRegistro").css({ "background-color": "rgb(252, 210, 7)", "visibility": "visible", "font-size": "1.5em", "color": "#121e2d !important" });
$(".MarcoResultados").hide("slow", function () {
});
setTimeout(function () {
$("#MensajeRegistro").css("visibility", "hidden");
}, 1550);
}
$(".number").keyup(function (event) {
var valor = $(this).val();
//var valor2 = valor.charAt(0);
$(this).val(valor);
});
$(".number").keypress(function (event) {
var valor = $(this).val();
if (event.keyCode < 48 || event.keyCode > 57) {
event.preventDefault();
}
});
below is my partial view
@model checa.Models.WrapperCla
@{
ViewBag.Title = "ChecarEntradas";
}
@section cs{
#dialog-confirm {
display:none;
}
}
@{Html.RenderPartial("~/Views/Checador/_MensajeRegistro.cshtml",Model);}
@using ( Ajax.BeginForm("Buscar", Model.singlemp, new AjaxOptions { UpdateTargetId = "BusquedaEmpleados", HttpMethod = "Post" }) )
{
@Html.Label("Nombres")
@Html.Label("Apellidos")
@Html.Label("Clave")
@Html.Label("Departamento")
}
These items will be permanently deleted and cannot be recovered. Are you sure?
@{Html.RenderPartial("~/Views/Checador/_EmpleadosEncontrados.cshtml",Model.Empleados);}
@section Scripts
{
function Confirmacion() {
var response = false;
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Cofirmar": function () {
noenvio(response);
$(this).dialog("close");
},
"Cancelar": function () {
response = false;
$(this).dialog("close");
}
}
});
return response;
}
function noenvio(response) {
response = false;
return response;
}
}
this one is another partial view which displays the query results of the partial view
@model checa.Models.WrapperCla
@foreach ( var epm in Model.Empleadoslist )
{
using ( @Ajax.BeginForm("Checar", epm, new AjaxOptions { UpdateTargetId = "MensajeRegistro", HttpMethod = "Post", OnSuccess = "desaparece(data, status, xhr)", OnBegin = "return Confirmacion()" },
new { Class = "empleadoForm" }) )
{
@{
String convertido = "";
if ( epm.Foto != null )
{
convertido = System.Convert.ToBase64String(epm.Foto);
}
}
Empleado:@epm.nombres @epm.apellidos
Numero Empleado:@epm.idd
Departamento:@epm.Departamento
}
}