如何在ASP.NET MVC 3中允许坏URL

时间:2011-01-28 05:16:44

标签: asp.net-mvc asp.net-mvc-3 razor

我想在url中传递一个参数,但localhost服务器告诉它是坏网址。我可以让他们在MVC 3中工作吗

网址是

http://localhost:6251/time/saturdau/first/second//nextparameter

你可以看到第三个参数在这里是空白的。当第4个参数通过而没有通过第3个参数时,此请求是否可以工作。

我的工作是做什么的。

2 个答案:

答案 0 :(得分:0)

这是不允许的。您可以使用可选参数,但它们必须是URL中的最后一个段。中间不能有可选参数。

答案 1 :(得分:0)

相反,如果传递的参数为null,你可以尝试传递像my_conventional_null_indicator

这样的东西。

所以不要让它看起来像这样

http://localhost:6251/time/saturdau/value1/34//70

这样做

http://localhost:6251/time/saturdau/value1/34/my_conventional_null_indicator/70

但最好的方法仍然是传统方式

http://localhost:6251/time/saturdau?param1=value1&param2=34&param3=&param4=70

或更好的方法是最大化RouteValueDictionary的功能。