tninis
Привет,
отключите EnableEndpointRouting на ConfigureServices и снова протестируйте его.
services.AddMvc(opt=>{opt.EnableEndpointRouting=false; });
образец автозагрузки.в CS
namespace CoreMVC.Test
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddMvc(opt=>{opt.EnableEndpointRouting=false; });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Образец Контроллера
namespace CoreMVC.Test.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
[Route("")]
[Route("bilar")]
[Route("bilar/Index")]
public IActionResult Index()
{
return View();
}
[Route("bilar/{state}")]
public IActionResult Privacy(string state)
{
return View();
}
}
}