ASP:NET MVC 4のエリアに関する記事(「名前の競合を避ける方法」のセクション)に続きます。ルーティングはエリアと同じ名前のコントローラを見つけません
ファイルEpicAreaRegistration.cs内容::
私のディレクトリ構造を私はMVC 5を使用していますが、私は、バージョン4からのすべての機能が利用可能であり、バージョン5にを動作するはずと仮定します
namespace App1.Web.UI.Areas.Epic
{
public class EpicAreaRegistration : AreaRegistration
{
public override string AreaName
{
get{ return "Epic"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRouteLocalized(
name: "Epic_default",
url: "Epic/{controller}/{action}/{id}",
defaults: new { controller = "Pm", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "App1.Web.UI.Areas.Epic.Controllers" }
);
}
}
}
マイプロジェクトのApp_Start - > RouteConfig.csファイルの内容:UP DATEが名前空間
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "App1.Web.UI.Controllers" } // according to article namespace must be added here, so ASP.NET router distinguishes between request: e
);
}
}
を修正そして最後に、私はプロジェクトのディレクトリコントローラでEpicController.csファイルを持っている:私はに移動すると
namespace App1.Web.UI.Controllers
{
public class EpicController : Controller
{
public ActionResult Browse()
{
return View();
}
}
}
を:(それを見つけた)それが動作http://localhost:7300/Epic/Pmが、 http://localhost:7300/Epic/Browseは機能しません(404 - 見つかりません)。私は何を逃したのですか?
私の前提は、要求が何らかの種類のルーティングテーブルを経由するということです。エリアでエピック/ブラウズが見つからない場合は、プロジェクトのルートコントローラフォルダに移動する必要があります。それはまた、私はのApplication_Start
内のすべての分野public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
....
私は実際のアプリケーション名を隠してしまったため、名前空間を投稿したときにタイプミスしてくれてありがとうございました。そのため、App1という名前が付けられましたが、まだ動作しません。気づいた+1。 – broadband