如何解决ASP.NET MVC - 找不到区域内的 WEB API
我有 1 个包含 API 的区域,但我无法调用它,也不明白为什么,这里是代码:
不在区域:WebApiConfig
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",routeTemplate: "api/{controller}/{action}/{id}",defaults: new { id = RouteParameter.Optional }
);
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); //per convertire in .json
}
Global.asax:
protected void Application_Start()
{
AreaRegistration.RegisterallAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
然后在区域里面有一个名为 Tyre24AreaRegistration 的文件:
public class Tyre24AreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Tyre24";
}
}
public override void Registerarea(AreaRegistrationContext context)
{
context.MapRoute(
"Download","Tyre24/api/{controller}/{action}/{id}",new {controller = "Download",id = UrlParameter.Optional }
); //not working <
context.MapRoute(
"Tyre24_default","Tyre24/{controller}/{action}/{id}",new { action = "Index",id = UrlParameter.Optional }
);
}
}
查看:
<div> @Html.ActionLink("DownloadExportTyres","DownloadExportTyres","Download",new { area = "Tyre24" },null)</div>
控制器:
public class DownloadController : ApiController
{
[HttpGet]
public IHttpActionResult DownloadExportTyres()
{
......
}
}
我实际上尝试了许多在 stackoverflow 中的“解决方案”,但在这种情况下没有任何帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。