I think, you can add custom binder for int type.
Demo: http://dotnetfiddle.net/VSMQzw
Useful links:
- http://haacked.com/archive/2011/03/19/fixing-binding-to-decimals.aspx/
- Default ASP.NET MVC 3 model binder doesn't bind decimal properties
- http://www.codeproject.com/Articles/551576/ASP-NET-MVC-Model-Binding-and-Data-Annotation
updated
Based on Haacked article:
using System;
using System.Globalization;
using System.Web.Mvc;
public class IntModelBinder : IModelBinder
{
#region Implementation of IModelBinder
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
ValueProviderResult valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
ModelState modelState = new ModelState { Value = valueResult };
bindingContext.ModelState[bindingContext.ModelName] = modelState;
object actualValue = null;
try
{
actualValue = Int32.Parse(valueResult.AttemptedValue, NumberStyles.Number, CultureInfo.InvariantCulture);
}
catch (FormatException e)
{
modelState.Errors.Add(e);
}
bindingContext.ModelState.Add(bindingContext.ModelName, modelState);
return actualValue;
}
#endregion
}
And in the Application_Start event (probably in the Global.asax), add:
ModelBinders.Binders.Add(typeof(int), new IntModelBinder());