小编Dan*_*rte的帖子

路由 ASP.NET Core 5 - id 的默认值始终返回 0

我有一个 ASP.NET Core 5 项目,我需要的很简单。我想在id值中指示路由中的默认 int 值。但是,当我跟踪控制器时,它总是返回 id 作为0null

public IActionResult Seccion(int id)
{
   
    return View();
}
Run Code Online (Sandbox Code Playgroud)

这是我的 Start.up 文件

 app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=podcast}/{action=Index}/{id?}");

            endpoints.MapControllerRoute(
                        name: "historias",
                        pattern: "seccion/{id=300}",
                        defaults: new { controller = "Podcast", action = "Seccion" });

        });
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我希望输入时https://localhost:xxx/podcast/seccion/historias调用Seccion()操作方法并默认id设置为。300但该来的id总会到来0

c# asp.net-mvc routes asp.net-core

6
推荐指数
1
解决办法
1208
查看次数

标签 统计

asp.net-core ×1

asp.net-mvc ×1

c# ×1

routes ×1