0

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?

6
  • 3
    I think you should contact phil haack via its blog rather than asking here. Kindly Commented Nov 6, 2012 at 10:44
  • What does the "red line" say? Commented Nov 6, 2012 at 10:47
  • But he well not even notice it, as it was written 1 and a half year ago. Thank you for sugestion Commented Nov 6, 2012 at 10:48
  • Error 2 The type or namespace name 'Binders' does not exist in the namespace 'RoomReservation.Wep.ModelBinders' (are you missing an assembly reference?) C:\Visual_Studio_2010_Workspace\RoomReservation\RoomReservation\RoomReservation.Wep\Global.asax.cs 40 26 RoomReservation.Wep Commented Nov 6, 2012 at 10:48
  • @TunAntun Personally, I get questions to articles I've written 10 years ago and if the asker is nice and polite, I usually always answer questions. Commented Nov 6, 2012 at 10:48

2 Answers 2

5

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())
Sign up to request clarification or add additional context in comments.

2 Comments

You error 'Binders' does not exist in the namespace 'RoomReservation.Wep.ModelBinders' clearly tells it is treating ModelBinders as part of namespace instead of referring it as a type.
Great answer. I went with the workaround first (changing the code), but then I realised thanks to the first part of your answer, because it's generated code, that I should just change that namespace in my own solution.
0

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

2 Comments

System.Web.Http.ModelBinding namespace is not having a class called Binders. ref:msdn.microsoft.com/en-us/library/…
Yes, when I do the above statement change I get Add underscored. So I guess, you are wright, there is no Binders in ModelBinding

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.