I am trying to write Custom model binder but it is giving an error can any one told me where i am doing it wrong?
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Models
{
public class CustomModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
Ownership own = new Ownership();
own.name = controllerContext.HttpContext.Request.Form["fName"];
own.email = controllerContext.HttpContext.Request.Form["fEmail"];
own.PhoneNo = controllerContext.HttpContext.Request.Form["fPhoneNo"];
own.country = controllerContext.HttpContext.Request.Form["Country"];
own.address = controllerContext.HttpContext.Request.Form["Adres"];
own.office = controllerContext.HttpContext.Request.Form["Off"];
own.officeEmail = controllerContext.HttpContext.Request.Form["OffEmail"];
own.officeNo = controllerContext.HttpContext.Request.Form["OffNo"];
own.OwnershipType = controllerContext.HttpContext.Request.Form["OwnershipType"];
own.ProductId = controllerContext.HttpContext.Request.Form["ProductId"];
return own;
}
}
}
Error
"'CustomModelBinder' does not implement interface member 'System.Web.Mvc.IModelBinder.BindModel(System.Web.Mvc.ControllerContext, System.Web.Mvc.ModelBindingContext)'
ModelBinders.Binders.Add(typeof(Ownership), new CustomModelBinder());
in global.asax? You also needpublic void MyAction([ModelBinder(typeof(CustomModelBinder))] Ownership owner)
in the controllerbin
obj
and theTemporary ASP.NET Files
(the location of the last one depends on what kind of web server you are using)