我有一个导航页面(angularJS控制器),从中可以转到特定的MVC控制器:
$scope.Department = function () {
window.location.href = appSetting.publish + "/Settings/Departments";
}
有一个SettingsController
:
public class SettingsController : Controller
{
public ActionResult Departments()
{
return View();
}
}
这很有效,直到我尝试使用它:
$scope.Department = function () {
window.location.href = appSetting.publish + "/appsettings/Departments";
}
和控制器:
[RoutePrefix("appsettings")]
public class SettingsController : Controller
{
[Route("Departments")]
public ActionResult Departments()
{
return View();
}
}
它转到Http错误404找不到页面。 我提到了this。
还有其他帖子提到了去global.asax类并添加以下代码行:
GlobalConfiguration.Configure(WebApiConfig.Register);
在WebApiConfig
:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Attribute routing.
config.MapHttpAttributeRoutes();
// Convention-based routing.
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
在RouteConfig
:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}
}
我有这些。我检查了NuGet包中是否有AttributeRouting(ASP.NET MVC)和AttributeRouting(ASP.NET Web API),并且两者都没有安装,所以我只尝试使用AttributeRouting(ASP.NET MVC),但它给我带来了同样的错误。