如何在MVC3中验证我的文本框 [英] How can i validate my Textbox in MVC3
本文介绍了如何在MVC3中验证我的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
虽然我不是.Net的新手,但我是MVC的新手,我通过做简单的练习来学习MVC3,这里我要求我需要用不同的方式验证我的文本框场景如
1)用户输入文本框中的数据不是吗?
2)文本框只能接受数字
3)在Textbox1中输入的值应始终大于Textbox2
4)在文本框中输入的No不应为零
5)电子邮件ID格式,密码格式
请帮我解决代码如何实现上述验证,是否有任何验证控件,如我们的ASP.NET,即必填字段,正则表达式,范围验证器等...
谢谢
Ramu
解决方案
嗨Ramu,
我很高兴您正在尝试MVC。当我倾向于首先学习MVC时,我也很喜欢你。
MVC中的验证可以通过两种方式完成,因为我知道
1)使用Model类
http://msdn.microsoft.com/en-us/library/dd410404(v = vs.90).aspx [ ^ ]
2)不使用Model类
试试这个LINK [ ^ ]
ASP.NET MVC中的模型验证 [ ^ ]
希望这对您有所帮助。
问候,
RK
Hii to all,
Though iam not new to .Net but iam new to MVC,iam learning MVC3 by doing simple exercises,here i got an requirement that i need to validate my textbox with different scenarios like
1)Wheather the user entered the data in the textbox r not?
2)Textbox should accept only digits
3)The No entered in Textbox1 should be always greater than Textbox2
4)The No entered in the Textbox Should not be Zero
5)E-mail ID format,Password Format
please help me with code how can i achieve above validations,is there any validation controls like in our ASP.NET i.e Required Field,Regular Expression,Range Validator etc...
Thanks
Ramu
解决方案
Hi Ramu,
I am glad that you are trying MVC. I am also like you when I tend to learn MVC at first.
Validation in MVC can be done in two ways as I know
1) Using Model class
http://msdn.microsoft.com/en-us/library/dd410404(v=vs.90).aspx[^]
2) Without using Model class
Try this LINK[^]
Model Validation in ASP.NET MVC[^]
Hope this might be helpful for you.
Regards,
RK
这篇关于如何在MVC3中验证我的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文