im stuck with this very strange problem.
i have an API Controller named AttendanceController
derived from APIControllerFA
which is inturn derived from ApiController
here is the code
public class AttendanceController : ApiControllerFA
{
public HttpResponseMessage PostAttendance([ModelBinder(typeof(AttendanceRegistrationModelBinder))]AttendanceRegistrationModel model)
{
//checking model state for errors
//throw new Exception("Just to throw an error ");
...........
As can be seen on the PostAttendance method i have a custom ModelBinder
named AttendenceRegistrationModelBinder
for which this is the code
public class AttendanceRegistrationModelBinder : DefaultModelBinder
{
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor)
{
if (propertyDescriptor.Name == "formJson")
{
string val = bindingContext.ValueProvider.GetValue(propertyDescriptor.Name).AttemptedValue;
dynamic jsonVal = JsonConvert.DeserializeObject(val);
propertyDescriptor.SetValue(bindingContext.Model, jsonVal);
return;
//SetProperty(controllerContext, bindingContext,propertyDescriptor,jsonVal);
}
base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
}
}
but when i try to access this controller using the Fiddler. i get an error saying
Could not create a 'IModelBinder' from 'AttendanceRegistrationModelBinder'. Please ensure it derives from 'IModelBinder' and has a public parameterless constructor
what am i doing wrong here?