MVC 3和razor的路由问题
我希望我的路线看起来像这样:
/Products/Image11_full.jpg
我的 Razor 看起来像这样:
<a rel="pgroup" title="@image.Name" href="@Url.RouteUrl("Image", new { controller = "Products", action = "Image", imageId = image.ImageId, size = "full" })" >
我的路线看起来像这样:
routes.MapRoute(
"Image",
"Products/Image{imageId}_{size}.jpg", // URL pattern, e.g. ~/Products/Image/
new { controller = "Products", action = "Image" }, // Defaults will also match "GetSmallImage"
new { imageId = @"\d+", size = @"\(full\|small\|medium\)" }
);
我以太没有得到任何东西(当我使用路线名称时)或者我得到一条看起来像这样的路线这 /Products/Image?imageId=11&size=full 这意味着它没有找到我的路线。
有人看到我做错了什么吗?
谢谢 欧文
I want my route to look like this:
/Products/Image11_full.jpg
My Razor looks like this:
<a rel="pgroup" title="@image.Name" href="@Url.RouteUrl("Image", new { controller = "Products", action = "Image", imageId = image.ImageId, size = "full" })" >
My route looks like this:
routes.MapRoute(
"Image",
"Products/Image{imageId}_{size}.jpg", // URL pattern, e.g. ~/Products/Image/
new { controller = "Products", action = "Image" }, // Defaults will also match "GetSmallImage"
new { imageId = @"\d+", size = @"\(full\|small\|medium\)" }
);
I ether don't get anything (when I use a route name) or I get a route that look like this
/Products/Image?imageId=11&size=full which means it didn't find my route.
Anyone see what I'm doing wrong?
Thanks
Irv
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的尺寸限制不正确。像这样定义它:
Your size constraint is not correct. Define it like this:
从
RouteUrl
调用中删除controller
和action
。 (因为它们不在 URL 参数中)Remove
controller
andaction
from theRouteUrl
call. (Since they aren't in the URL parameters)