Hi rani,
In order to use Areas right click on the project in solution explorer and select Add. Then select Area...
Then provide suitable name for your Area name and click Add.
This will generate all the required files and added the dependencies.
However the Application's Startup code may required additional changes for things to work end to end.
You need to add the following code to the Configure method in your Application's Startup class.
app.UseMvc(routes =>
{
routes.MapRoute(
name : "areas",
template : "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
So the Configure method will look like below.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "area",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Then you need to add the controller in the Areas folder and add [Area] attribute to Controllers.
[Area("Area1")]
public class HomeController : Controller
Refer below link for details.
https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-5.0