My ASP.NET Core project's new action is not working and not called while my the other controllers and actions are working fine.
This is my controller code:
using Microsoft.AspNetCore.Mvc;
namespace PresentationLayer.Areas.dashboard.Controllers
{
public class Weblog : Controller
{
[Area("dashboard")]
public IActionResult Index()
{
return View();
}
public IActionResult AddWeblog()
{
return View();
}
}
}
My index
action is working fine, but my AddWeblog
method is not called anymore.
The name of the actions are the same as the name of views.
This controller is in area while the other controllers before this is working fine with their actions but after this time when I add any controller just index action work why?
I cleaned the solution, restarted Visual Studio, and deleted the controller and rewrote it, but nothing is working.
The Area
attribute is required to be applied on the Controller class but not the Action method.
[Area("dashboard")]
public class Weblog : Controller
{
...
}
Also, make sure that you have added the area route in the middleware pipeline.
For ASP.NET Core below version 6
app.UseEndpoints(endpoints =>
{
endpoints.MapAreaControllerRoute(
name: "Dashboard",
areaName: "Dashboard",
pattern: "dashboard/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
app.MapAreaControllerRoute(
name: "Dashboard",
areaName: "Dashboard",
pattern: "dashboard/{controller=Home}/{action=Index}/{id?}");
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");