c# - Implement custom ModelBinder ASP.NET MVC -
i having same problem many people had - model binder doesn't accept localized decimal input. in of threads, here , other forums, recommended solution implementing custom modelbinder
.
my problem solutions somehow don't work me. let's use solution example: comma decimal seperator in asp.net mvc 5
when reference namespaces, 2 errors remain:
error cs0115 'decimalmodelbinder.bindmodel(controllercontext, modelbindingcontext)': no suitable method found override ...
and
error cs0173 type of conditional expression cannot determined because there no implicit conversion between 'bool' , 'decimal'
where second 1 references entire return
statement.
did change in mvc framework, code outdated, or doing wrong?
the code ended is:
using system; using system.collections.generic; using system.linq; using system.web; using system.web.modelbinding; using system.web.mvc; namespace aetmuzickaoprema.app_start { public class decimalmodelbinder : system.web.modelbinding.defaultmodelbinder { public override object bindmodel(controllercontext controllercontext, system.web.modelbinding.modelbindingcontext bindingcontext) //first error { var valueproviderresult = bindingcontext.valueprovider.getvalue(bindingcontext.modelname); return valueproviderresult == null ? base.bindmodel(controllercontext, bindingcontext) : convert.todecimal(valueproviderresult.attemptedvalue); //second error } } }
model property in question:
[required] [range(typeof(decimal), "0", "999999999")] public decimal price { get; set; }
it seems trying achieve property-level binding such this?:
[propertybinder(typeof(propertybbinder))] public ilist<int> propertyb {get; set;}
if correct, post offers solution: custom model binder property
thanks.
Comments
Post a Comment