I have created one view ,in which i have one text box,i want to put required field validation on that text box.
@Html.TextBox("txtFirst", "", htmlAttributes: new {@maxlength="9"})
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First I must say the best way to do validation in MVC is to put the Data Annotation attributes above the properties in your model like with this:
The good thing in this approach(except that it’s usually less to write) that it work client-side and Server-side as well.
If you want to do the validation in the view and not in the
Modelfor some reason, you simply need to add therequiredclass to the textbox: