[英]Re-direct image requests in RouteConfig file (ASP.NET MVC)?
I'm having a problem using a jQuery plugin in an ASP.NET MVC Project, where images are being searched for in locations that don't exist. 我在ASP.NET MVC项目中使用jQuery插件时遇到问题,该项目在不存在的位置搜索图像。
I am receiving missing image errors like such: 我收到像这样的缺失图像错误:
GET http://localhost:51710/Home/img/chesspieces/wikipedia/bN.png 404 (Not Found)
But I have no idea why it seems to be searching for images inside of localhost/Home
like that? 但是我不知道为什么看起来要像这样在localhost/Home
内部搜索图像?
I want to search inside a content folder for the images of course, (eg \\Content\\chessboard.js\\img
), not a view/view controller like localhost/Home
. 我想在内容文件夹中搜索图像(例如\\Content\\chessboard.js\\img
),而不是像localhost/Home
这样的视图/视图控制器。
Why is this, and how can I achieve what I want? 为什么会这样,如何实现我想要的?
My routeconfig
file is still in it's default state: 我的routeconfig
文件仍处于默认状态:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Edit: 编辑:
Here's the line in chessboard.js, where I can change the route after localhost/Home
, but not localhost/Home
itself: 这是chessboard.js中的行,我可以在其中更改localhost/Home
之后的路线,但不能更改localhost/Home
本身:
cfg.pieceTheme = 'img/chesspieces/wikipedia/{piece}.png';
使用绝对路径:
cfg.pieceTheme = '/img/chesspieces/wikipedia/{piece}.png'; // note the '/'
There is a very helpful Url extension to point to appropriate location of your content files (like images): 有一个非常有用的网址扩展名,可以指向内容文件(例如图像)的适当位置:
@Url.Content
Which makes it possible to get your files from appropriate content directories. 这样便可以从适当的内容目录中获取文件。
@Url.Content("~/Content/chessboard.js/img")
In case there is no possibility to use Razor syntax inside this file you could try this: 如果无法在此文件中使用Razor语法,则可以尝试以下操作:
cfg.pieceTheme = "~/Content/chessboard.js/img/chesspieces/wikipedia/{piece}.png';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.