C# HttpRequestMessage.CreateErrorResponse()不';不存在
我刚刚阅读了,它有这个示例,但是下面提供的示例代码不会编译,因为C# HttpRequestMessage.CreateErrorResponse()不';不存在,c#,asp.net-web-api,C#,Asp.net Web Api,我刚刚阅读了,它有这个示例,但是下面提供的示例代码不会编译,因为CreateErrorResponse()在HttpRequestMessage中不存在。有人知道为什么吗 public class ValidateModelAttribute : ActionFilterAttribute { public override void OnActionExecuting(HttpActionContext actionContext) {
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);
}
}
}
CreateErrorResponse
是一种扩展方法,使用System.Net.Http添加代码>
文档:CreateErrorResponse
是一种扩展方法,使用System.Net.Http添加代码>
文档:@Augustin Seifert-您如何知道HttpRequestMessage具有扩展方法?它没有在汇编类中说明任何内容,好的,谢谢。但是为什么他们不在HttpRequestMessage页面上提到它呢?@Augustin Seifert-你怎么知道HttpRequestMessage有扩展方法?它没有在汇编类中说明任何内容,好的,谢谢。但是为什么他们不在HttpRequestMessage页面上提及它呢?