如何在MVC4中进行验证 [英] How to give validation in MVC4
本文介绍了如何在MVC4中进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个html文本框:
< input type =textname =UserName/> ;
如何对此文本框进行验证。我需要使用Html代码而不使用@html.Editor的文本框。
请帮助
Hi,
I have an html textbox:
<input type="text" name="UserName"/>
How can i give validation to this textbox. I need the textbox using Html code not using @html.Editor for.
Please help
推荐答案
您可以使用javascript进行客户端验证。你应该参考这个页面。
使用JavaScript进行客户端验证 [ ^ ]
You can have a client side validation using javascript. You should refer to this page.
Client Side Validation using JavaScript[^]
我刚学到的另一个技巧是,如果您使用的是HTML 5,只需在输入标签中添加required属性,即<; br />
< input type =textname =UserNamerequired />
它会提交此文本框时请求值。
Another trick that I just learn is if you are using HTML 5, you can simply add "required" attribute to your input tag i.e;
<input type="text" name="UserName" required/>
It will ask for a value when you submit this textbox.
这篇关于如何在MVC4中进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文