0
我正在尝试将constraint
添加到controller
。我可能有这个完全错误的,但我的理解是,如果route
不匹配,那么应该不是调用constructor
方法?添加MVC约束仍然调用控制器方法
这里是我的路线:
routes.MapRoute(
"UserProfile",
"UserProfile/{userName}",
new { controller = "UserProfile", action = "Index" },
new { userName = @"[a-zA-Z]+" }
);
所以,我认为,因为我问了userName
,当我打的网址mywebsite/UserProfile
应该不匹配?请有一些纠正我的想法,如果有人可以帮忙,以获得route
而不是调用constructor
方法,因为userName
丢失,这将是很好的。
使用Phil Haacks路由调试器,当我删除'Default'路由时失败。我从Route Debugger的输出中得到一个'NO MATCH',即使我指定了'userName' –
@Neil Knight,你的控制器叫做UserProfileController还是只有'UserProfile'并且它包含一个'Index'动作? –
它被称为'UserProfileController'并且包含'Index'动作。这个问题似乎与正则表达式有关。当我为''*'改变'+'时,它就起作用了。 –