コンテンツが異なる特定のアクションで (Facebook からのクレジット処理用の) 着信要求があるため、それを処理するための異なるモデル クラスがあります。
これは私の行動です:
public ActionResult Index([ModelBinder(typeof(FacebookCreditModelBinder))] IFacebookRequest facebookRequest)
{
if (facebookRequest is FacebookPaymentsGetItemsRequest)
{
// do whatever
}
}
そして、これは私のモデル バインダーです。
public class FacebookCreditModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var binder = new DefaultModelBinder();
// how to change the model here in the bindingContext?
return binder.BindModel(controllerContext, bindingContext);
}
}
FacebookPaymentsGetItemsRequest
たとえば、着信変数「メソッド」が「payments_get_items」で、if メソッドが「payments_status_update」の場合にオブジェクトを作成したいのですFacebookPaymentsStatusUpdateRequest
が、bindingContext でモデルのタイプを変更する方法がわかりません。カスタムモデルバインダーでモデルのタイプを変更することはできますか?
他のアプローチ: BindModel でも試してみましたが、正しいオブジェクトを返すことができましたが、既定のモデル バインダーによって埋められていないため、すべてのプロパティが null です。
public override object BindModel(ControllerContext controllerContext,
ModelBindingContext bindingContext)
{
NameValueCollection form = controllerContext.HttpContext.Request.Form;
if (form.Get("method") == "payments_get_items")
{
return new FacebookPaymentsGetItemsRequest();
}
...