助けAndriy Tolstoyの答えは、私は、整数の性質の一部を動作させるためにかかわらず、それを少し変更しなければなりませんでした。
public class TestRequestModelBinder : IModelBinder
{
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelType != typeof(TestRequest)) return false;
bindingContext.Model = new TestRequest();
var parameters = actionContext.Request.RequestUri.ParseQueryString();
typeof(TestRequest)
.GetProperties()
.ToList()
.ForEach(property =>
{
var parameterValue = parameters[property.Name];
if (parameterValue == null) return;
typeof(TestRequest).GetProperty(property.Name).SetValue(bindingContext.Model, Convert.ChangeType(parameterValue, property.PropertyType));
});
return bindingContext.ModelState.IsValid;
}
}
主な変更点は、プロパティの元PropertyType
に値をキャストすることである。ここでは
は場合にそれが誰かを助け、私が使用更新ModelBinder
です。
web apiに固有のカスタムバインダーを作成しないと、自動的にこれを行う方法はありません。メソッドのシグネチャで 'default(TestRequest)'を使用することを考えていた場合は、http://stackoverflow.com/a/4066357/1260204も参照してください。 – Igor