在asp.net core 3.0中属性路由无法正常工作

问题描述 投票:0回答:1

我试图将我的应用程序从asp.net core 2.1迁移到使用属性路由的3.0

我的启动文件的ConfigureServices和Configure方法:

public void ConfigureServices(IServiceCollection services)
{
    services.ConfigureOptions(typeof(ABCClass));
    services.AddTransient<ITagHelperComponent, XYZTagHelperComponent>();            
    services.AddMvc();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
       app.UseDeveloperExceptionPage();
    }
    app.UseStaticFiles();
    app.UseMvcWithDefaultRoute();
}

我已将services.AddMvc();替换为services.AddMvc(options => options.EnableEndpointRouting = false);以禁用端点路由

我的操作方法:

[Route("")]
[Route("Machines")]
public async Task<ViewResult> GetMachinesAsync()
{
    return View("MachineView");
}

[我的应用程序首次加载MachineView时,但是当我尝试在其上调用相同的操作方法时,出现404错误(找不到页面)

。cshtml文件中的操作调用:

<li class="nav-item">
    <a class="nav-link"
       href="@Url.Action("GetMachinesAsync", "Machine")">
       Machines 
    </a>
</li>

如果我在这里遗漏了一些东西,或者在配置用于路由的中间件时做错了,可以请帮我。

预先感谢。

asp.net-core asp.net-core-2.1 asp.net-core-3.0 asp.net-core-routing
1个回答
0
投票

默认情况下,在asp.net core 3.0中将修剪控制器动作名称的异步后缀。

© www.soinside.com 2019 - 2024. All rights reserved.