ファイル アップロード アクションにカスタム モデル バインダーを実装しました。ファイルのアップロードがサーバーによってドロップされ、部分的なデータで BindModel メソッドが呼び出される場合があります (ここでは ContentLenght と TotalBytes が一致しません)。カスタム モデル バインダーからのアクションの実行を中止したいのですが、その方法を教えてください。
public class OptionModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var optionModelName = GetOptionModelName(controllerContext);
if (optionModelName != null) return null// !!!How to abort Action execution?!!! here
Trace.TraceInformation(optionModelName);
var model = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(optionModelName);
bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType());
return base.BindModel(controllerContext, bindingContext);
}
public class OptionModelBinderAttribute : CustomModelBinderAttribute
{
public override IModelBinder GetBinder()
{
return new OptionModelBinder();
}
}
[HttpPost]
public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> clientUpload, [OptionModelBinder]IOptionViewModel formData)
{
}