首页 > 解决方案 > asp.net核心路由参数始终为空

问题描述

我有一个 actionresult 方法,它接受一个字符串作为参数,但是每当我使用 url 查询该方法时,该参数始终为空。

abc是路由中id的值。但是当我查看堆栈跟踪时,我看不到方法接受任何值。

http://localhost:47268/admin/AllQuarterEvent/abc

public IActionResult AllQuarterEventByMap(string map)
{
    return View(_staffMethods.GetQuarterEventsByMap(map));
}

标签: asp.net-coreroutesasp.net-core-mvc

解决方案


请尝试此解决方案:

  [HttpGet("admin/AllQuarterEventByMap/{map}")]
  public IActionResult AllQuarterEventByMap([fromRoute] string map)
    {
        return View(_staffMethods.GetQuarterEventsByMap(map));
    }

推荐阅读