Asp.net mvc 4 从区域中的asp.NET WebAPI获取响应时遇到问题
我正在尝试将ASP.NET Web API(来自MVC 4)添加到我的项目。。。。。但是我很难从Area/WebAPI/Controller获得任何响应(不太确定哪里出了问题…) 我安装了路由调试器,如果我转到主页。。。我看到了路线Asp.net mvc 4 从区域中的asp.NET WebAPI获取响应时遇到问题,asp.net-mvc-4,asp.net-web-api,Asp.net Mvc 4,Asp.net Web Api,我正在尝试将ASP.NET Web API(来自MVC 4)添加到我的项目。。。。。但是我很难从Area/WebAPI/Controller获得任何响应(不太确定哪里出了问题…) 我安装了路由调试器,如果我转到主页。。。我看到了路线 Matches Current Request Url Defaults Constraints DataTokens False api/{controller}/{action}/{id} action = Index, id = Url
Matches Current Request Url Defaults Constraints DataTokens
False api/{controller}/{action}/{id} action = Index, id = UrlParameter.Optional (empty) Namespaces = OutpostBusinessWeb.Areas.api.*, area = api, UseNamespaceFallback = False
False {resource}.axd/{*pathInfo} (null) (empty) (null)
True {controller}/{action}/{id} controller = Home, action = Index, id = UrlParameter.Optional (empty) (empty)
True {*catchall} (null) (null) (null)
看来路线已经设置好了
接下来我在“api”区域有一个PlansController,它只是由“AddNew”生成的默认ApicController
你知道为什么吗?有什么需要配置的吗?将其更改为:
// GET /api/<controller>
public IEnumerable<string> GetMultiple(int id)
{
return new string[] { "value1", "value2" };
}
我的控制器:
public class MyApiController : ApiController
{
public IQueryable<MyEntityDto> Lookup(string id) {
..
}
工作正常。将其更改为:
// GET /api/<controller>
public IEnumerable<string> GetMultiple(int id)
{
return new string[] { "value1", "value2" };
}
我的控制器:
public class MyApiController : ApiController
{
public IQueryable<MyEntityDto> Lookup(string id) {
..
}
工作正常。ASP.NET MVC 4在开箱即用的领域不支持WebApi Martin Devillers提出了一个解决方案: 您还可以在我对类似问题的回答中了解更多详细信息(特别是对于便携式区域的支持):
ASP.NET MVC 4在开箱即用的领域不支持WebApi Martin Devillers提出了一个解决方案: 您还可以在我对类似问题的回答中了解更多详细信息(特别是对于便携式区域的支持):
对不起,我没有包括完整的来源。。。。默认实现确实有一个get(int-id)方法,如果将它放在一个区域中会怎么样?对不起,我没有包含完整的源代码。。。。默认实现确实有一个get(intid)方法,如果将它放在一个区域中会怎么样?
public class MyApiController : ApiController
{
public IQueryable<MyEntityDto> Lookup(string id) {
..
}
http://localhost/MyWebsite/api/MyApi/Lookup/hello