HttpRequestMessage.CreateErrorResponse() 不存在

Bac*_*ave 1 c# asp.net-web-api

我刚刚阅读了有关Web API 模型验证的内容,它有这个示例,但是下面提供的示例代码将无法编译,CreateErrorResponse()因为HttpRequestMessage. 有谁知道为什么?

public class ValidateModelAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            if (actionContext.ModelState.IsValid == false)
            {
                actionContext.Response = actionContext.Request.CreateErrorResponse(
                    HttpStatusCode.BadRequest, actionContext.ModelState);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)