私はこの非常に奇妙な問題で立ち往生しています。私は派生した
という名前のAPIコントローラーを持っています。これは
ここから派生したコードですAttendanceController
APIControllerFA
ApiController
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 ");
...........
PostAttendanceメソッドに見られるように、これがコードであるというModelBinder
名前のカスタムがありますAttendenceRegistrationModelBinder
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);
}
}
しかし、フィドラーを使用してこのコントローラーにアクセスしようとすると。エラーが発生します
Could not create a 'IModelBinder' from 'AttendanceRegistrationModelBinder'. Please ensure it derives from 'IModelBinder' and has a public parameterless constructor
私はここで何が間違っているのですか?