我的bootstrap验证无法在MVC4 Razor中运行。 [英] my bootstrap validation not working in MVC4 Razor .

查看:72
本文介绍了我的bootstrap验证无法在MVC4 Razor中运行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/这是我放在视图页面上的java脚本/





< script type = '  text / javascript'> 
$( document )。ready( function (){
$(< span class =code-string>' #defaultForm')。bootstrapValidator({
message:' 此值无效'
feedbackIcons:{
有效:' glyphicon glyphicon-ok'
无效:' glyphicon glyphicon-remove'
验证:' glyphicon glyphicon -refresh'
},
字段:{
用户名:{
消息:' 用户名无效'
validato rs:{
notEmpty:{
message:' 用户名是必需的,并且可以\' t为空'
},
stringLength:{
min: 6
max:< span class =code-digit> 30 ,
message:' 用户名必须是超过6个字符且少于30个字符'
},
/ * remote:{
url:'remote.php',
message:'用户名不可用'
},* /

regexp:{
regexp:/ ^ [a-zA-Z0-9 _ \。] + $ /,
消息:' 用户名只能包含字母,数字,点和下划线'
}
}
},
电子邮件:{
验证器:{
notEmpty:{
message :' 电子邮件地址是必填项,且不能为空
},
emailAddress:{
message:' 输入不是有效的电子邮件地址'
}
}
},
密码:{
验证人:{
notEmpty:{
消息:' 密码是必需的,不能为空'
}
}
}
}
})
.on(' success.form.bv' function (e){
// 阻止表单提交
e.preventDefault();

// 获取表单实例
var $ form = $(e.target);

// 获取BootstrapValidator实例
var bv = $ form.data(' bootstrapValidator') ;

// 使用Ajax提交表单数据
$。 post($ form.attr(' action'),$ form.serialize(), function (结果){
console .log(result);
},' json');
});
});


< / script>
< pre lang = text>< pre lang = HTML>
< / pre >

< pre lang = c#>
< pre lang = xml>& lt; form id =& ; QUOT; defaultForm&安培; QUOT;方法=安培; QUOT;交&安培; QUOT; class =& quot; form-horizo​​ntal& quot; &安培; GT;
& lt; div class =& quot; form-group& quot;& gt;
& lt; label class =& quot; col-lg-3 control-label& quot;& gt;用户名& lt; / label& ; GT;
& lt; div class =& quot; col-lg-5& quot;& gt;
& lt; input type =& quot; text& quot; class =& quot; form-control& quot;名称=安培; QUOT;用户名&安培; QUOT; /&安培; GT;
& lt; / div& gt;
& lt; / div& gt;

& lt; div class =& quot; form-group& quot;& gt;
& lt; label class =& quot; col-lg-3 control-label& quot;& gt;电子邮件地址& lt; /标签&安培; GT;
& lt; div class =& quot; col-lg-5& quot;& gt;
& lt; input type =& quot; text& quot; class =& quot; form-control& quot;名称=安培; QUOT;电子邮件&安培; QUOT; /&安培; GT;
& lt; / div& gt;
& lt; / div& gt;

& lt; div class =& quot; form-group& quot;& gt;
& lt; label class =& quot; col-lg-3 control-label& quot;& gt; Password& lt; / label& ; GT;
& lt; div class =& quot; col-lg-5& quot;& gt;
& lt;输入类型=& quot;密码& quot; class =& quot; form-control& quot;名称=安培; QUOT;密码&安培; QUOT; /&安培; GT;
& lt; / div& gt;
& lt; / div& gt;

& lt; div class =& quot; form-group& quot;& gt;
& lt; div class =& quot; col-lg-6 col-lg-offset-3& quot;& gt;
& lt; button type =& quot; button& quot; class =& quot; btn btn-primary& quot; & gt;注册& lt; / button& gt;
& lt; / div& gt;
& lt; / div& gt;
& lt; / form& gt; < / pre >




< / pre > < pre lang = < span class =code-string> HTML>

解决方案

document )。ready( function (){


' #defaultForm')。bootstrapValidator({
message:' < span class =code-string>此值无效',
feedbackIcons:{
有效:' glyphicon glyphicon-ok'
无效:' glyphicon glyphicon-remove'
验证:' glyphicon glyphicon-refresh'
},
字段:{
用户名:{
message:< span class =code-string>' 用户名无效'
验证人:{
notEmpty:{
消息:' 用户名是必填项,且不能为空'
},
stringLength:{
min: 6
max: 30
消息:' 我们ername必须大于6且少于30个字符'
},
/ * 远程:{
url:'remote.php',
消息:'用户名不可用'
},* /

regexp:{
regexp:/ ^ [a-zA-Z0-9_\。] +


/,
消息: ' 用户名只能包含字母,数字,点和下划线'
}
}
},
电子邮件:{
验证人:{
notEmpty:{
message:' 电子邮件地址是必需的,不能为空'
},
emailAddress:{
message:' < span class =code-string>输入不是有效的电子邮件地址'
}
}
},
密码:{
验证器:{
notEmpty:{
message:' 密码是必需的,但不能是空的'
}
}
}
}
})
.on( ' success.form.bv' function (e){
< span class =code-comment> // 防止表单submi ssion
e.preventDefault();

// 获取表单实例
VAR

/This is my java script which placed on view page/


<script type='text/javascript'>
    $(document).ready(function () {
        $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                username: {
                    message: 'The username is not valid',
                    validators: {
                        notEmpty: {
                            message: 'The username is required and can\'t be empty'
                        },
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: 'The username must be more than 6 and less than 30 characters long'
                        },
                        /*remote: {
                            url: 'remote.php',
                            message: 'The username is not available'
                        },*/
                        regexp: {
                            regexp: /^[a-zA-Z0-9_\.]+$/,
                            message: 'The username can only consist of alphabetical, number, dot and underscore'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: 'The email address is required and can\'t be empty'
                        },
                        emailAddress: {
                            message: 'The input is not a valid email address'
                        }
                    }
                },
                password: {
                    validators: {
                        notEmpty: {
                            message: 'The password is required and can\'t be empty'
                        }
                    }
                }
            }
        })
            .on('success.form.bv', function (e) {
                // Prevent form submission
                e.preventDefault();

                // Get the form instance
                var $form = $(e.target);

                // Get the BootstrapValidator instance
                var bv = $form.data('bootstrapValidator');

                // Use Ajax to submit form data
                $.post($form.attr('action'), $form.serialize(), function (result) {
                    console.log(result);
                }, 'json');
            });
    });
   

</script>
<pre lang="text"><pre lang="HTML">
</pre>

<pre lang="c#">
<pre lang="xml">&lt;form id=&quot;defaultForm&quot; method=&quot;post&quot; class=&quot;form-horizontal&quot; &gt;
                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;col-lg-3 control-label&quot;&gt;Username&lt;/label&gt;
                    &lt;div class=&quot;col-lg-5&quot;&gt;
                        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;username&quot; /&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;col-lg-3 control-label&quot;&gt;Email address&lt;/label&gt;
                    &lt;div class=&quot;col-lg-5&quot;&gt;
                        &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;email&quot; /&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;label class=&quot;col-lg-3 control-label&quot;&gt;Password&lt;/label&gt;
                    &lt;div class=&quot;col-lg-5&quot;&gt;
                        &lt;input type=&quot;password&quot; class=&quot;form-control&quot; name=&quot;password&quot; /&gt;
                    &lt;/div&gt;
                &lt;/div&gt;

                &lt;div class=&quot;form-group&quot;&gt;
                    &lt;div class=&quot;col-lg-6 col-lg-offset-3&quot;&gt;
                        &lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; &gt;Sign up&lt;/button&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/form&gt;</pre>




</pre><pre lang="HTML">

解决方案

(document).ready(function () {


('#defaultForm').bootstrapValidator({ message: 'This value is not valid', feedbackIcons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: { username: { message: 'The username is not valid', validators: { notEmpty: { message: 'The username is required and can\'t be empty' }, stringLength: { min: 6, max: 30, message: 'The username must be more than 6 and less than 30 characters long' }, /*remote: { url: 'remote.php', message: 'The username is not available' },*/ regexp: { regexp: /^[a-zA-Z0-9_\.]+


/, message: 'The username can only consist of alphabetical, number, dot and underscore' } } }, email: { validators: { notEmpty: { message: 'The email address is required and can\'t be empty' }, emailAddress: { message: 'The input is not a valid email address' } } }, password: { validators: { notEmpty: { message: 'The password is required and can\'t be empty' } } } } }) .on('success.form.bv', function (e) { // Prevent form submission e.preventDefault(); // Get the form instance var


这篇关于我的bootstrap验证无法在MVC4 Razor中运行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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