部分视图中的图像,CSS,JS文件夹路径已更改 [英] Images, CSS, JS folder path changed in partial views
问题描述
我有一个简单的mvc web应用程序,其中我有一个菜单,如
home,services,contactus当我点击服务菜单时,新服务控制器调用并打开服务索引视图,这个查看有服务详细信息,还有一个阅读更多按钮,当我点击阅读更多按钮我想显示更多细节,如该服务的描述,所有这些都正常工作,问题是,当我点击服务上的Readmore链接按钮view它丢失了我的JS和Css文件夹的路径,所以我的_Layout.cshtml有滑块,当我点击阅读更多按钮时它没有显示该滑块的图像它正确地显示了其他细节但是我的图像的路径和Css,JS受到干扰,我发现了问题,并检查了这是正确的路径,但是当我将鼠标悬停在img标签上时,它会显示出类似的路径
http:// localhost:60553 / Service / Images / img / rsz_malibu-2.png无法加载资源
我的意思是它是loo王我的CSS JS和服务文件夹中的图像而不是根文件夹如何解决这个问题
我尝试了什么:
我已经检查了我的滑块的方法,它在代码中有正确的路径但是当我在浏览器中检查元素时它显示以下路径
http:/ /localhost:60553/Service/Images/img/rsz_malibu-2.png
它是在SErvice文件夹而不是root中找到图像然后Images / img / rsz_malibu-2.png
I have a simple mvc web application , in which i have a menu like
home,services,contactus when i click the service menu the new service controller invokes and service Index view opened, and this view have service details and also a read more button , when i click the read more button I want to show the more details like description of that service, all these things are working properly , The issue is that when i click the Readmore linkbutton on service view It loses the Path of my JS and Css folder , so my _Layout.cshtml having the slider and it did not show the images of that slider when i clicked the Read more button it shows the other details properly but the path of my Images and Css,JS get disturbed , I inspact the issue and check that
this is correct path but when i hover on img tag it show the path like that
http://localhost:60553/Service/Images/img/rsz_malibu-2.png Failed to load resource
I mean it is looking my CSS JS and images in Service Folder instead of root folder how to fix that
What I have tried:
I have check the method of my slider it is having correct path in code but when i inspect the element in browser it shows the below path
http://localhost:60553/Service/Images/img/rsz_malibu-2.png
It is finding the image in SErvice Folder instead of in root then Images/img/rsz_malibu-2.png
推荐答案
我认为你的问题出在你的GetData方法中,特别是在这里:
I think your issue is in your GetData method, specifically here:
src = "../Images/img/" + fileName
我认为您需要将其改为
I think you need to change that to something like
src = HttpContext.Current.Server.MapPath("~/Images/img/" + fileName);
您目前正在这样做的方式,该呼叫与您的请求相关。使用Server.MapPath将URL映射到相对于服务器的图像。
The way you are currently doing it, the call is relative to your request. Using Server.MapPath maps your URL to the image relative to the server.
这篇关于部分视图中的图像,CSS,JS文件夹路径已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!