我不明白ASP.net的根源;我在想什么吗?
这是我的根源:

 routes.MapRoute(
                name: "ChampionID",
                url: "Champion/ChampionById/id",
                defaults: new { controller = "Champion", action = "ChampionById", id = "5" }
            );


这是我的控制者:

public class ChampionController : Controller
{
    public ActionResult ChampionById(string x)
    {
        ChampionId ch = new ChampionId();
        ch.Id = x;
        return View(ch);
    }


如果您能帮助我,我将很感激

最佳答案

忘记路线。只需连接所有路线,然后将路线作为如下属性即可:

public class ChampionController : Controller
{
    [Route("Champion/ChampionById/{id}")]
    public ActionResult ChampionById(string id)
    {
       ChampionId ch = new ChampionId();
       ch.Id = id;
       return View(ch);
    }
}


x也应该是id。然后只需删除routes.MapRoute。然后,确保您有一个名为ChampionById的相应cshtml文件。

10-07 12:09