在MVC Razor VIEW中使用JQuery进行必要的字段验证 [英] Required field validation using JQuery in MVC Razor VIEW

查看:91
本文介绍了在MVC Razor VIEW中使用JQuery进行必要的字段验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一个DropDown列表和一个文本框的MVC RAZOR视图。这两个(属性)不属于特定型号。



如何设置文本框和下拉列表的强制性验证?



我试过用



< script type = text / javascript>

$(document) .ready(function(){

$(&input。#trackcodeid")。validate();

});

< /脚本>



trackcodeid是输入元素名称。



我收到以下错误。



0x800a01b6 - Microsoft JScript运行时错误:对象不支持属性或方法'验证'







任何人都可以告诉我哪里错了。



谢谢你们。(div class =h2_lin>解决方案

(document).ready(function(){


(&input。#trackcodeid")。validate();

});

< / script> ;



trackcodeid是输入元素名称。



我收到以下错误。



0x800a01b6 - Microsoft JScript运行时错误:对象不支持属性或方法'验证'







任何人都可以告诉我哪里错了。



谢谢你们。


< blockquote>给这个文本框上课

new {@class =required}

尝试它会起作用

请注意它是否有问题你

I have a MVC RAZOR view with one DropDown list and a text box. These two (attributes) are not belonging to a particular model.

How can I set the mandatory validations for Text Box and drop down list?

I tried using

<script type=text/javascript>
$(document).ready(function () {
$(&input.#trackcodeid").validate();
});
</script>

trackcodeid is input element name.

I am getting the below error.

0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'validate'



Can anyone tell where I am wrong.

Thank you in andvance.

解决方案

(document).ready(function () {


(&input.#trackcodeid").validate();
});
</script>

trackcodeid is input element name.

I am getting the below error.

0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'validate'



Can anyone tell where I am wrong.

Thank you in andvance.


give class to that textbox
new { @class = "required" }
try it will work
please mark if it worjks for you


这篇关于在MVC Razor VIEW中使用JQuery进行必要的字段验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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