Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 控制器';s动作参数不';不接受/_C#_Asp.net Mvc_Routes - Fatal编程技术网

C# 控制器';s动作参数不';不接受/

C# 控制器';s动作参数不';不接受/,c#,asp.net-mvc,routes,C#,Asp.net Mvc,Routes,我有控制员的行动 public string Index(string id) { return id; } 我在Global.asax.cs中只有这条路线 routes.MapRoute( "Default", "{id}", new { controller = "Start", action = "Index", id = UrlParameter.Optional }

我有控制员的行动

    public string Index(string id)
    {
        return id;
    }
我在Global.asax.cs中只有这条路线

routes.MapRoute(
            "Default", 
            "{id}", 
            new { controller = "Start", action = "Index", id = UrlParameter.Optional }              
        );
对于像这样的url“http://localhost/stuff“和”http://localhost/hello“它起作用了。但它对url不起作用,比如“http://localhost/stuff/add". 如何修复它?

在id之前添加通配符(星号):

     routes.MapRoute(
            "Default",
            "{*id}",
            new {controller = "Start", action = "Index", id = UrlParameter.Optional}
            );

您希望它如何工作?/home/staff必须显示字符串“home/staff”。但是现在“/hello”显示“hello”(正常工作)和/hello/test显示错误“id”不能包含“/”。这不是使用路由的正确方法。