0

我有一个基本请求类型..

类 RequestBase

{
   public string inputId;
   public string derivedid;
}

和继承的类型..

class RequestA : RequestBase
{
   public string name;
}

class RequestB : RequestBase
{
   public string color;
}

我有一个 webapi 服务,有些动作采用 RequestA 的输入参数,有些采用 RequestB

[HttpPost]
 [MyFilter]
 [ActionName("Process1")]
  public HttpResponseMessage Process1(RequestA request)
  {  
      //do something with request.derivedId
  }

 [HttpPost]
 [MyFilter]
 [ActionName("Process2")]
  public HttpResponseMessage Process2(RequestB request)
  {  
      //do something with request.derivedId
  }

我有一个 actionfilter 从请求中获取 inputId 并生成一个derivedId

 public override void OnActionExecuting(HttpActionContext actionContext)
    {
        RequestBase request = (RequestBase)actionContext.ActionArguments["request"];
        string inputId = request.inputId;

        string derivedId = inputId + "123";
        // ?? somehow inject derivedId back into the actionContext so that my controller methods can access?
    }

正如我上面的评论所述,我想填充 derivedId 字段并让我的控制器方法可以访问它。

提前致谢

4

1 回答 1

0

此线程中已经描述了这个问题的一些解决方案 - 其中一个应该适合您:

ASP.NET MVC 将对象从自定义操作筛选器传递到操作

于 2013-01-25T20:06:06.303 回答