0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[ASP.NET] MVC エリアを作る

Posted at

クイックメモ、ASP.NET 3.X MVCでエリアを作るとき

新しいエリアを作る

プロジェクト配下のAreasフォルダーで右クリック、追加、エリアを選択。

image.png

エリアの名前を入力

image.png

ScaffoldingReadMe.txtを確認、でもその通りにしては動かない。

ScaffoldingReadMe.txtが生成されるので確認。

Scaffolding has generated all the files and added the required dependencies.

However, the Application's Startup code may require additional changes for things to work end to end.
Add the following code to the Configure method in your Application's Startup class if not already done:

app.UseMvc(routes =>
{
  routes.MapRoute(
    name : "areas",
    template : "{area:exists}/{controller=Home}/{action=Index}/{id?}"
  );
});

app.UserEndpointsを更新

Startup.cs既存のapp.UserEndpointsを確認

既存は下記

app.UseEndpoints(endpoints =>{
  endpoints.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
    endpoints.MapRazorPages();
});

ScaffoldingReadMe.txt通りにすると正しく動作しないので、下記のように書き直し。

app.UseEndpoints(endpoints =>
{
  endpoints.MapControllerRoute(
    name: "areaRoute",
    pattern: "{area:exists}/{controller}/{action}",
    defaults: new { action = "Index" });

  endpoints.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

  endpoints.MapRazorPages();
});
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?