MVC 3和razor的路由问题

发布于 2024-10-15 09:02:04 字数 779 浏览 0 评论 0原文

我希望我的路线看起来像这样:

/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

默嘫て 2024-10-22 09:02:04

您的尺寸限制不正确。像这样定义它:

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" }
            );

Your size constraint is not correct. Define it 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" }
            );
痴骨ら 2024-10-22 09:02:04

RouteUrl 调用中删除 controlleraction。 (因为它们不在 URL 参数中)

Remove controller and action from the RouteUrl call. (Since they aren't in the URL parameters)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文