I am just following a MVC 5 book and it is creating a custom model binder for its shopping cart. What he has in the book is:
“public class CartModelBinder : IModelBinder {
private const string sessionKey = "Cart";
public object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext) {”
Excerpt From: Adam Freeman. “Pro ASP.NET MVC 5.” iBooks.
And when I started typing and created my class it automatically created this:
public class CartModelBinder: IModelBinder
{
private const string sessionKey = "Cart";
public bool BindModel(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext)
{
That one returns an objects and accepts different parameters than the one IDE created for me. So now what should we do?
The book is referring to System.Web.Mvc.IModelBinder
; your implementation is using System.Web.ModelBinding.IModelBinder
.
There are actually 3 different IModelBinder
interfaces defined that you may encounter. The third definition is contained in System.Web.Http and is used for Web API.
This answer covers the why. In brief, they are different implementations for different purposes ( MVC, Web Forms, and Web API).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With