ASP.NET MVC:生成缩略图的问题......需要帮助!

时间:2021-12-31 02:08:46

Ok, so i'm new to asp.net mvc and i'm trying to make a web application photo gallery. I've posted once on here about this issue i am having of trying to generate thumbnails on-the-fly on the page instead of the actual full-size images. Basically, the functionality i am looking for is to be able to have thumbnails on the page and then be able to click the images to see the full-size version. I am pulling the images and images info from an XML file. So, i did this so i could display them dynamically and so it would be easier to make changes later. Later, i am going to add functionality to upload new images to specific galleries (when i figure out how to do that as well). I am providing a link to download the project i am working on so you can see the code. I would appreciate any help with this! Thanks! URL to project: http://www.diminished4th.com/TestArtist.zip Ryan

好的,所以我是asp.net mvc的新手,我正在尝试创建一个Web应用程序照片库。我已经在这里发布了一次关于这个问题我试图在页面上实时生成缩略图而不是实际的全尺寸图像。基本上,我正在寻找的功能是能够在页面上有缩略图,然后能够单击图像以查看完整大小的版本。我从XML文件中提取图像和图像信息。所以,我这样做,所以我可以动态显示它们,因此以后更容易进行更改。稍后,我将添加将新图像上传到特定图库的功能(当我弄清楚如何做到这一点时)。我提供了一个链接来下载我正在处理的项目,以便您可以看到代码。我很感激任何帮助!谢谢!项目的URL:http://www.diminished4th.com/TestArtist.zip Ryan

1 个解决方案

#1


1  

In your global.asax.cs file, you have defined the Default route before your Thumbs route so the Galleries part of the url is mapped to a non-existent Galleries controller instead of the Gallery controller (as specified in your second route):

在global.asax.cs文件中,您已经在Thumbs路由之前定义了默认路由,因此URL的Galleries部分映射到不存在的Galleries控制器而不是Gallery控制器(如第二条路径中所指定):

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
     new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
    "Thumbs", // Route name
    "Galleries/getThumb/{image}", // URL with parameters
     new { controller = "Gallery", action = "getThumb", id = UrlParameter.Optional }, // Parameter defaults
      new string[] { "TestArtist.Controllers" }
 );

Simply define the Thumbs route before the Default route and you should be all good:

只需在默认路由之前定义Thumbs路由,您应该都很好:

routes.MapRoute(
    "Thumbs", // Route name
    "Galleries/getThumb/{image}", // URL with parameters
     new { controller = "Gallery", action = "getThumb", id = UrlParameter.Optional }, // Parameter defaults
      new string[] { "TestArtist.Controllers" }
 );

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
     new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

#1


1  

In your global.asax.cs file, you have defined the Default route before your Thumbs route so the Galleries part of the url is mapped to a non-existent Galleries controller instead of the Gallery controller (as specified in your second route):

在global.asax.cs文件中,您已经在Thumbs路由之前定义了默认路由,因此URL的Galleries部分映射到不存在的Galleries控制器而不是Gallery控制器(如第二条路径中所指定):

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
     new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
    "Thumbs", // Route name
    "Galleries/getThumb/{image}", // URL with parameters
     new { controller = "Gallery", action = "getThumb", id = UrlParameter.Optional }, // Parameter defaults
      new string[] { "TestArtist.Controllers" }
 );

Simply define the Thumbs route before the Default route and you should be all good:

只需在默认路由之前定义Thumbs路由,您应该都很好:

routes.MapRoute(
    "Thumbs", // Route name
    "Galleries/getThumb/{image}", // URL with parameters
     new { controller = "Gallery", action = "getThumb", id = UrlParameter.Optional }, // Parameter defaults
      new string[] { "TestArtist.Controllers" }
 );

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
     new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);