我发现这个答案有帮助,但我不确切知道如何提供的示例帮助。它似乎只是“重命名”一个已经准备好的资料夹。
在我的情况下,我被张贴到一个外部服务,将张贴像“body-plain”的东西,我无法控制名称。所以我修改这个样品看起来像这样:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class ParameterNameMapAttribute : ActionFilterAttribute
{
public string InboundParameterName { get; set; }
public string ActionParameterName { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
object value = filterContext.RequestContext.HttpContext.Request[InboundParameterName];
if (filterContext.ActionParameters.ContainsKey(ActionParameterName))
{
filterContext.ActionParameters[ActionParameterName] = value;
}
else
{
throw new Exception("Parameter not found on controller: " + ActionParameterName);
}
}
}
这实际上发生在参数“身体平原”为例,它映射到我我的控制器上定义的ActionParameter。像这样:
[ParameterNameMap(InboundParameterName = "body-plain", ActionParameterName = "bodyPlainText")]
[ParameterNameMap(InboundParameterName = "Thread-Topic", ActionParameterName = "alternateSubject")]
public HttpStatusCodeResult Process(string token, string timestamp, string signature, string subject, string sender, string recipient, string bodyPlainText, string alternateSubject)
{
你真的需要使用几许? – 2010-08-11 18:04:55
是否需要**才能成为用户名? – Buildstarted 2010-08-11 18:05:27
根本不需要。令人费解的是MVC没有想到这种情况。我实际上并没有使用它,只是好奇它是否存在......或者它为什么不存在。 – 2010-08-11 19:06:51