微软的MVC:手动触发表单验证微软、表单、MVC

2023-09-05 02:06:03 作者:南栀向暖

没有人知道是否有一种方法来触发手动。净MVC应用程序客户端表单验证?我要做到以下几点:

does anyone know if there is a way to trigger the client side form validation in a .Net MVC app manually? I want to do the following:

<script type="text/javascript">
    if([form valid]) {
        //do something
    }
</script>

我已经通过code看着MicrosoftMvcValidation.js但没有找到一个方法,我可以在表格上调用。

I already looked through the code in MicrosoftMvcValidation.js but didn't find a method I could call on the form.

推荐答案

我认为你正在寻找可以在这里找到验证: http://www.phpvs.net/2010/04/26/manually-validate-an-asp-net-mvc-form-on-the-client-side-with-microsoftmvcvalidation-js-and-jquery/

I think the validation you are looking for can be found here: http://www.phpvs.net/2010/04/26/manually-validate-an-asp-net-mvc-form-on-the-client-side-with-microsoftmvcvalidation-js-and-jquery/

该协议是你需要Sys.Mvc.FormContext,其上有一个.validate的背景下。这是需要被调用。只是检查出的博客文章,你会很高兴。 : - )

The deal is you need context of Sys.Mvc.FormContext, which has a .validate on it. This is what needs to be called. Just check out the blog post and you will be happy. :-)