开发者

How to bind a complex object to an ActionFilterAttribute ActionParameters?

开发者 https://www.devze.com 2022-12-29 19:56 出处:网络
My question is fairly simple: I have a custom ActionFilterAttribute which looks like this (simplified for readability):

My question is fairly simple: I have a custom ActionFilterAttribute which looks like this (simplified for readability):

public class DynamicModuleActionAttribute : ActionFilterAttribute {
    public override void OnActionExecuting(ActionExecutingContext filterContext) {
        filterContext.ActionParameters["module"] = new MyObject();
        base.OnActionExecuting(filterContext);
    }
}

Then, my controller action should look like this:

[DynamicModuleAction]
public ActionResult Edit(Module module) {
    // do some logic here
    return View();
}

With this code, I'm getting an ArgumentNullException in the DefaultModelBinder.

Of course I could receive an o开发者_Python百科bject module in the action and then cast it to Module, but, obviously, I'm trying to avoid this workaround.

Any clues?

Thanks everyone!

0

精彩评论

暂无评论...
验证码 换一张
取 消