My validation is not working. I dont know what i am missing, i read from here ,
@{
Validation.Add("number", Validator.Integer("Must be integer"));
if(IsPost)
{
if(Validation.IsValid())
{
<div>Number Submitted!</div>
}
}
}
.......
<form action="" method="post">
<div>
@Html.Label("Insert a number:", "number")
@Html.TextBox("number",Request["number"])
@Html.ValidationMessage("number")
</div>
<div>
<input type="submit" value="submit">
</div>
</form>
I can type any value, and validation message shows nothing, am i missing something?
Thanks.
You should also add a Required
validator:
Validation.Add("number",
Validator.Required("Gimme something, please?"),
Validator.Integer("Must be integer")
);