我正在使用ASP.NET MVC 3中新的不显眼的验证功能验证表单.
因此,我没有编写代码来设置jQuery验证以开始验证我的表单.这一切都是通过加载jQuery.validate.unobtrusive.js库来完成的.
不幸的是,我需要打个招呼'你确定吗?' 表单有效但在提交之前的消息框.使用jQuery验证,你会在初始化时添加选项handleSubmit:
$("#my_form").validate({
rules: {
field1: "required",
field1: {email: true },
field2: "required"
},
submitHandler: function(form) {
if(confirm('Are you sure?')) {
form.submit();
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是在使用不显眼的库时,您不需要初始化.
在这种情况下,我可以在哪里/如何添加提交处理程序?
谢谢
如何阻止用户双击我的注册表单上的提交按钮,这是一个ajax局部视图?
我很遗憾地问,因为这已经被问到了.我现在找不到一个明确的工作答案.禁用该按钮会阻止提交.使用var javascript clickcount + alert + return_false不会重置.
环境:asp.net mvc3
查看:
表单显示onload:@RenderPage("_SignupForm.cshtml")
提交使用:
@using (Ajax.BeginForm("Index", "Signup", null,
new AjaxOptions
{
UpdateTargetId = "signupForm",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
LoadingElementId="progress"
}
))
Run Code Online (Sandbox Code Playgroud)
提交控制权: <input type="submit" value="Sign up" />
SignupController:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(SignupModel formvalues)
{
Thread.Sleep(5000);
string errors = "";
if (TryValidateModel(formvalues))
{
errors = SignupAPI.Signup(formvalues); //includes custom validation
}
if (ModelState.IsValid == false || string.IsNullOrEmpty(errors) == false)
{
ViewBag.Errors = errors; …Run Code Online (Sandbox Code Playgroud) jquery ×1