I'm writing ASPNET Core web page.
I created two razor view libraries and in each one I created file List.cshtml and controller:
WebPage.Users
List.cshtml
UsersController.cs
WebPage.Clients
List.cshtml
ClientsController.cs
Both controllers have Index method:
public class ClientsViewController : Controller
{
public IActionResult Index()
{
return this.View("~/Pages/Views/List.cshtml");
}
}
public class UsersViewController : Controller
{
public IActionResult Index()
{
return this.View("~/Pages/Views/List.cshtml");
}
}
StartUp code:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddMvc()
.AddApplicationPart(typeof(UsersController).Assembly)
.AddApplicationPart(typeof(ClientsController).Assembly);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>{
endpoints.MapControllerRoute(
name: "usersViewController",
pattern: "modules/users/{action}",
defaults: new {
controller = "UsersView",
action = "Index"
});
endpoints.MapControllerRoute(
name: "clientsViewController",
pattern: "modules/clients/{action}",
defaults: new {
controller = "ClientsView",
action = "Index"
});
});
}
Now the problem is when I open page "modules/clients/" in browser
it returns view from WebPage.Users.Views. I want to return view from WebPage.Clients.Views assembly.
How can I do this?