ModelBinder int :
public class IntModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
double parsedValue;
if (double.TryParse(value.AttemptedValue, out parsedValue))
{
if ((parsedValue < int.MinValue || parsedValue > int.MaxValue))
{
var error = "LOCALIZED ERROR MESSAGE FOR FIELD '{0}' HERE!!!";
bindingContext.ModelState.AddModelError(bindingContext.ModelName, string.Format(error, value.AttemptedValue, bindingContext.ModelMetadata.DisplayName));
}
}
return base.BindModel(controllerContext, bindingContext);
}
}
: ModelBinders.Binders.Add(typeof(int), new IntModelBinder()); .
P.S. , , :)