您好伙伴我在发送ajax请求之前尝试显示对话框,但我没有根据点击的按钮获得正确的响应。但我只得到两个结果或显示对话框,但请求已发送或从不发送请求。
我不想使用纯jquery,因为我的强类型视图和我的控制器accion期待一个模型 所以我认为这将是我需要解决的另一个非常大的问题。
请给我一些建议
这是我的布局
<!DOCTYPE html>
<html lang="es-ES">
<head>
<title>Checador</title>
<link rel="stylesheet" href="@Url.Content("~/Content/Estilos.css")">
<meta charset="utf-8">
@RenderSection("cs", required: false)
</head>
<body>
<div class="linea"> </div>
<table border="0" align="center" cellpadding="0" cellspacing="0" id="principal">
<tr>
<td id="Cuadro" align="left" valign="middle">
<span class="slogan">SOME TITLE</span><br />
<span class="subslogan">BLAH BLAH</span>
</td>
<td id="seccion" valign="top" align="right">
<div class="lineainfo">
@using ( Html.BeginForm("LogOff", "Login", FormMethod.Post, new { id = "logoutForm" }) )
{
@Html.AntiForgeryToken()
<a href="javascript:document.getElementById('logoutForm').submit()">Cerrar Sesion</a>
}
</div>
</td>
</tr>
<tr>
<td colspan="2" valign="top" id="Central">
<div>
@RenderBody()
</div>
</td>
</tr>
<tr>
<td align="right" id="Pie_Pagina" colspan="100%"><span>Abarrotes Monterrey © 2014 Mexico(Es)</span></td>
</tr>
</table>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@RenderSection("scripts", required: false)
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script>
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();
}
});
</script>
</body>
</html>
下面是我的部分视图
@model checa.Models.WrapperCla
@{
ViewBag.Title = "ChecarEntradas";
}
@section cs{
<style>
#dialog-confirm {
display:none;
}
</style>
}
<div id="MensajeRegistro">
@{Html.RenderPartial("~/Views/Checador/_MensajeRegistro.cshtml",Model);}
</div>
@using ( Ajax.BeginForm("Buscar", Model.singlemp, new AjaxOptions { UpdateTargetId = "BusquedaEmpleados", HttpMethod = "Post" }) )
{
@Html.Label("Nombres")<input type="text" id="Nombres" name="Nombres" />
@Html.Label("Apellidos")<input type="text" id="Apellidos" name="Apellidos" />
@Html.Label("Clave")<input type="text" id="idd" name="idd" class="number" />
@Html.Label("Departamento")<input type="text" id="Departamento" name="Departamento" />
<input type="submit" value="Buscar" />
}
<div id="dialog-confirm" title="Empty the recycle bin?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
<div id="BusquedaEmpleados" class="ResultadosEmpleados">
@{Html.RenderPartial("~/Views/Checador/_EmpleadosEncontrados.cshtml",Model.Empleados);}
</div>
@section Scripts
{
<script type="text/javascript">
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;
}
</script>
}
这是另一个部分视图,显示部分视图的查询结果
@model checa.Models.WrapperCla
<div class="MarcoResultados">
@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" }) )
{
<div class="empleado">
@{
String convertido = "";
if ( epm.Foto != null )
{
convertido = System.Convert.ToBase64String(epm.Foto);
}
<img class="fempleado" src="data:image;base64,@convertido" width="80" height="80" />
}
<label>Empleado:@epm.nombres @epm.apellidos</label>
<label>Numero Empleado:@epm.idd</label>
<label>Departamento:@epm.Departamento</label>
<input type="submit" value="Checar" />
</div>
}
}
</div>