简体   繁体   中英

ASP.NET MVC 3 model binding not working for me?

This is the line that is not working:

ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder())

To be more precise. Binders is highlated.

I found this article by Phil Haack.

I did all it said, added refrences to using System.Web.Http.ModelBinding.Binders; Added class public class DecimalModelBinder : IModelBinder to a new folder and told to Global.ascx about the folder. But the red line keeps showing underneath the Binders . Can you help me?

From the error it looks like it is treating the ModelBinders as namespace (which is present in your project) instead of the framework class.

Try using the below line which will resolve the ambiguity.

 System.Web.Mvc.ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder())

The compiler interprets the reference to ModelBinders as a reference to RoomReservation.Wep.ModelBinders. Try using

System.Web.Http.ModelBinding.Binders.Add(typeof(decimal), new DecimalModelBinder())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM