提交使用数据注释与DIV / jQuery的形式MVC3 [英] Submit MVC3 form that uses Data Annotations with div/jquery

查看:98
本文介绍了提交使用数据注释与DIV / jQuery的形式MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有,我用一个输入类型=提交注册用户在页面上的形式。添加数据注释,一些自定义后,一些内置的,我想自定义输入的外观提交按钮才发现,我不能得到它来搭配这只是的div /链接页面上的其他按钮。所以,我想使它的使用jQuery提交之前,提交表单和数据注解的内置的通话和定制的jQuery的一个div。我想这样的:

So, I have a form on the page that I was using an input type="submit" to register users. After adding Data Annotations, some custom, some built-in, I wanted to customize the look of the input submit button only to find out that I cannot get it to match the other buttons on the page which are just divs/links. So, I would like to make it a div that uses jquery to submit the form and call of the data annotation's built-in and customized jquery before submitting. I tried this:

@using(Html.BeginForm(指数,注册,FormMethod.Post,新{@id =registerForm}))
  {

  < DIV ID =registerSubmit级=divSubmit>
        <一>注册< / A>
    < / DIV> }

$(#registerSubmit)。的onclick(函数(){
        $(#registerForm)提交()。
    });

但是,这不是为我工作。有没有一种方法能够正确提交并调用DA code?

But, that is not working for me. Is there a way to submit and call the DA code correctly?

推荐答案

这是我用它来达到同样的事情。

This is what I use to achieve the very same thing

$(document).ready(function () {

    var submitButton = document.getElementById("registerSubmit");

    submitButton.onclick = function (event) {
        // do cool stuff before submit like validation or confirmations, whatever
        if ($(this).valid()) {
            // more cool stuff
            $("#registerForm").submit();
        }
        return false;
    };
});

这篇关于提交使用数据注释与DIV / jQuery的形式MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆