I have the following set:
public class Account : AuditableTable, IAccount
{
}
public class Product : AuditableTable
{
}
public abstract class AuditableTable
[Range(0, 99, ErrorMessage = "Position must be between 0 and 99.")]
[DisplayName("Position")]
public int? Position { get; set; }
In my view:
<div class="adm_td0">
@Html.TextBoxFor(model => model.Account.Position, new { size = 4 })
</div>
<div class="adm_td0">
@Html.ValidationMessageFor(model => model.Account.Position)
</div>
When I enter a number greater than 99 the number is accepted. Does anyone have any idea why this is happening? When I check my source code I see
<input id="Product_Position" type="text" value="24788" size="4" name="Product.Position" data-val-range-min="0" data-val-range-max="99" data-val-range="Position must be between 0 and 99." data-val-number="The field Position must be a number." data-val="true">
But there’s no check on the page OR on the server.
On the page I have included the following Javascripts:
"~/Scripts/jquery/jquery-1.6.1.min.js"
I think I am missing something so there’s no client validation. BUT should there still not be server validation?
If I do validation on the client then do I need to include ALL of the following:
"~/Scripts/jquery.unobtrusive-ajax.min.js"
"~/Scripts/jquery.validate.js"
"~/Scripts/jquery.validate.unobtrusive.js"
Try changing your View code to this :
It should work
Also, You need to include
Otherwise your validations wont work on that page