I have a problem with area
in netcore 3.1, I add my endpoint on startup.cs,
app.UseEndpoints(endpoints =>
{
// endpoints.MapControllers();
//endpoints.MapControllerRoute(
// name: "default",
// pattern: "{controller}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
add the service
services.AddControllersWithViews();//.AddNewtonsoftJson(); ;
services.AddRazorPages();
but it’s routing on this way, what obviously doesn’t work
controller/action?area=area
Example
Patients/Create?area=Medical
This is the way than I call it (by legacy purpose)
<a class="btn btn-primary" href="@Url.Action("Create", "Patients", new { area = "Medicals" })">
New Patient</a>
I try in the classic way for netcore and trowme the same route
<a class="btn btn-primary" asp-action="Create" asp-controller="Patients" asp-area="Medicals"> New Patient</a>
I have the Package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 3.1.9 Installed, than use to be the main problem with razor
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The solution it’s so stupid, the order for the area configuration it’ important, so, area need to be set first
endpoints.MapControllerRoute(
name: "default",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0