Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
Asp.net mvc 3 MVC路由未被调用_Asp.net Mvc 3 - Fatal编程技术网

Asp.net mvc 3 MVC路由未被调用

Asp.net mvc 3 MVC路由未被调用,asp.net-mvc-3,Asp.net Mvc 3,我已经登记了这条路线: context.MapRoute( "Manager", "manage/{id}/{action}", new { action = "index", controller = "manage", id = UrlParameter.Optional }, new string[] { "Web.Areas.Books.Controllers"

我已经登记了这条路线:

context.MapRoute(
                "Manager",
                "manage/{id}/{action}",
                new { action = "index", controller = "manage", id = UrlParameter.Optional },
                new string[] { "Web.Areas.Books.Controllers" }
            );
然后我有以下两个URL:

http://<site>/manage         <-- hits the index action of managecontroller
http://<site>/manage/publish <-- ALSO HITS INDEX VIEW even I have publish action

http:///manage         您希望第二段绑定到操作参数,但在路由中它是id参数

"manage/{id}/{action}"
使用
/manage/publish
URL,id参数的值将为
publish

框架找不到操作参数,因此它使用默认值并将其重定向到索引操作。您只能将末尾的参数作为可选参数

如果必须在中间指定和整数ID,可以通过定义约束来实现它。

context.MapRoute(
                "Manager",
                "manage/{id}/{action}",
                new { action = "index", controller = "manage" },
                new { id = @"\d+" }, //second segment has to be an integer
                new string[] { "Web.Areas.Books.Controllers" }
            );

其他URL应返回默认路由并正常工作。

@Projapati您需要为所需内容创建自定义视图引擎。@Projapati尝试我发布的路由。我最终将路由从/{id}/{action}更改为{action}/{id}
context.MapRoute(
                "Manager",
                "manage/{id}/{action}",
                new { action = "index", controller = "manage" },
                new { id = @"\d+" }, //second segment has to be an integer
                new string[] { "Web.Areas.Books.Controllers" }
            );