Is IModelBinder Signature Changed in MVC 5?

I just follow the MVC 5 book and she creates a custom mediator for her shopping cart. What does he have in the book:

"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)
        {

This returns objects and takes different parameters than the one IDE created for me. So what do we do now?

+4
source share
1 answer

The book refers to System.Web.Mvc.IModelBinder; your implementation uses System.Web.ModelBinding.IModelBinder.

Actually there are 3 different IModelBinderinterfaces that you can come across. The third definition is contained in System.Web.Http and is used for the web API.

, . , (MVC, Web Forms Web API).

+7

Source: https://habr.com/ru/post/1568920/


All Articles