.NET MVC 3触发(除提交按钮)不显眼的审定 [英] .Net Mvc 3 Trigger (other than submit button) Unobtrusive Validation
问题描述
我想这样
我想触发客户端验证在我看来,我的选择的事件。这可能是的onblur也许另一个按钮,但比提交按钮以外的东西。
I would like to trigger client-side validation in my View with an event of my choice. It could be 'onblur' maybe another button but something other than the submit button.
相关链接
<一个href=\"http://stackoverflow.com/questions/5785510/how-to-trigger-validation-without-using-a-submit-button\">How触发验证,而无需使用一个提交按钮
<一个href=\"http://xhalent.word$p$pss.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content\">Applying不显眼的jQuery验证在ASP.Net MVC 动态内容
我已经试过
给出一个不同的事件监听器,我已经解雇了,没有运气以下方法:
Given a various event listener, I've fired the following methods with no luck:
$(选择).validate();
$(选择).valid();
$ validator.unobtrusive.parseDynamicContent(选择);
$ validator.unobtrusive.parse($(选择));
摘要
所以我需要客户端验证火上某一特定事件(比其他提交),并显示相应的验证消息。我不觉得像任何标记/剃刀语法是必要的,因为客户端验证火灾的提交和所有相应的验证消息显示预期。
So I need client-side validation to fire on a given event (other than on submit) and show the corresponding validation messages. I dont feel like any of the Markup/Razor syntax is necessary as client-validation fires on submit and all the corresponding validation messages show as expected.
推荐答案
$('形式')。有效的()
应该工作。让我们来举例说明。
$('form').valid()
should work. Let's exemplify.
型号:
public class MyViewModel
{
[Required]
public string Foo { get; set; }
}
控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyViewModel());
}
}
查看:
@model MyViewModel
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.LabelFor(x => x.Foo)
@Html.EditorFor(x => x.Foo)
@Html.ValidationMessageFor(x => x.Foo)
}
<div id="validate">Hover here to trigger validation</div>
<script type="text/javascript">
$('#validate').hover(function () {
$('form').valid();
});
</script>
这篇关于.NET MVC 3触发(除提交按钮)不显眼的审定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!