از این Model Binder داخل پروژتون استفاده کنید :
public class DecimalModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var valueResult = bindingContext.ValueProvider
.GetValue(bindingContext.ModelName);
var modelState = new ModelState { Value = valueResult };
object actualValue = null;
try {
actualValue = Convert.ToDecimal(valueResult.AttemptedValue, CultureInfo.CurrentCulture);
}
catch (FormatException e) {
modelState.Errors.Add(e);
}
bindingContext.ModelState.Add(bindingContext.Model Name, modelState);
return actualValue;
}
}
و در Global.asax :
ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder());
bindingContext.ValueProvider.GetValue به طور پیشفرض Integer برمیگردونه و شما با استفاده از این Model Binder اون رو به Decimal تغییر میدید.
این مطلب + کامنت هاش رو به دقت بخونید ، متوجه مشکل میشید : http://stackoverflow.com/a/33711121/6661314





پاسخ با نقل قول