TunAntun
TunAntun

Reputation: 91

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 : IModelBinderto a new folder and told to Global.ascx about the folder. But the red line keeps showing underneath the Binders. Can you help me?

Upvotes: 0

Views: 1123

Answers (2)

Ramesh
Ramesh

Reputation: 13266

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())

Upvotes: 5

Marijn Deé
Marijn Deé

Reputation: 976

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())

Upvotes: 0

Related Questions