クイックメモ、ASP.NET 3.X MVCでエリアを作るとき
新しいエリアを作る
プロジェクト配下のAreasフォルダーで右クリック、追加、エリアを選択。
エリアの名前を入力
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();
});