MVC参数 - 路由为空

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

我在RouteConfig中有以下内容:

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{caseID}",
            defaults: new { controller = "Generator", action = "Index", caseID = UrlParameter.Optional }
        );
    }
}

而我的ActionResult方法:

public ActionResult Index(string caseID) {
    //some code
    var currentcase = new Something.Read(caseID);

    //some other code
    return View(model);
}

我的网址看起来像localhost / Generator / Index / dee7aff5-0a34-4965-936f-a08f1dae5c43

现在我的caseID应该是“dee7aff5-0a34-4965-936f-a08f1dae5c43”,但它是null,我无法弄清楚为什么。

谁能帮我?

UPDATE

如果网址是

本地主机/发生器/索引/?caseID = dee7aff5-0a34-4965-936f-a08f1dae5c43

代替

本地主机/发生器/索引/ dee7aff5-0a34-4965-936f-a08f1dae5c43

它运行良好。

asp.net asp.net-mvc model-view-controller
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.