问题描述
由于某些原因, Request.CreateResponse
现在是在VS2012的红,当我将鼠标悬停在IDE中说,使用
For some reason, Request.CreateResponse
is now "red" in VS2012 and when I hover over the usage the IDE says
无法解析符号'CreateResponse
下面是ApiController类:
Here is the ApiController Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Filters;
using GOCApi.Attributes;
using GOCApi.Models;
using GOCApi.Models.Abstract;
using AttributeRouting;
using AttributeRouting.Web.Http;
namespace GOCApi.Controllers
{
[RoutePrefix("Courses")]
public class CoursesController : ApiController
{
private ICoursesRepository _coursesRepository { get; set; }
public CoursesController(ICoursesRepository coursesRepository)
{
_coursesRepository = coursesRepository;
}
[GET("{id}")]
public HttpResponseMessage Get(int id)
{
var course = _coursesRepository.GetSingle(id);
if (course == null)
return Request.CreateResponse(HttpStatusCode.NotFound, "Invalid ID");
return Request.CreateResponse(HttpStatusCode.OK, course);
}
}
}
诚然,code编译并和工作,它只是真的很烦我看到屏幕上所有的红。此外,IntelliSense不现在当我键入 Request.CreateResponse
工作。这也可以用来工作,但我开始开发其他部分我的API,只是回来楼宇控制器,所以我不知道发生了什么。
Granted, the code does compile and works, it's just really annoying seeing all the "red" on my screen. Also, the intellisense doesn't work now when I type Request.CreateResponse
. This also used to work, but I started developing other parts to my API and just came back to building controllers so I do not know what happened.
有什么想法?
推荐答案
您需要添加到 System.Net.Http.Formatting.dll
的参考。在 CreateResponse
扩展方法定义在那里。
You need to add a reference to System.Net.Http.Formatting.dll
. The CreateResponse
extension method is defined there.
这篇关于网页API Request.CreateResponse的Htt presponseMessage没有智能感知VS2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!