2012-03-19 52 views
0

时失去跟踪的图像文件夹的这是我和它的工作原理:MVC局部视图使用jQuery

$(function(){ 
$('.slide-out-div').tabSlideOut({ 
     tabHandle: '.handle',      //class of the element that will become your tab 
     pathToTabImage: 'http://mhmiisdev2/images/contact_tab.gif', //path to the image for the tab //Optionally can be set using css 
     imageHeight: '122px',      //height of tab image   //Optionally can be set using css 
     imageWidth: '40px',      //width of tab image   //Optionally can be set using css 
     tabLocation: 'right',      //side of screen where tab lives, top, right, bottom, or left 
     speed: 300,        //speed of animation 
     action: 'click',       //options: 'click' or 'hover', action to trigger animation 
     topPos: '200px',       //position from the top/ use if tabLocation is left or right 
     leftPos: '20px',       //position from left/ use if tabLocation is bottom or top 
     fixedPosition: true      //options: true makes it stick(fixed position) on scroll 
    }); 
}); 

这就是我想要的东西,当我从一个控制器切换到另一个控制器,它不工作。请注意图片的路径不是绝对

$(function(){ 
    $('.slide-out-div').tabSlideOut({ 
     tabHandle: '.handle',      //class of the element that will become your tab 
     pathToTabImage: '/images/contact_tab.gif', //path to the image for the tab //Optionally can be set using css 
     imageHeight: '122px',      //height of tab image   //Optionally can be set using css 
     imageWidth: '40px',      //width of tab image   //Optionally can be set using css 
     tabLocation: 'right',      //side of screen where tab lives, top, right, bottom, or left 
     speed: 300,        //speed of animation 
     action: 'click',       //options: 'click' or 'hover', action to trigger animation 
     topPos: '200px',       //position from the top/ use if tabLocation is left or right 
     leftPos: '20px',       //position from left/ use if tabLocation is bottom or top 
     fixedPosition: true      //options: true makes it stick(fixed position) on scroll 
    }); 
}); 

的HTML完整性....

<div class="slide-out-div"> 
    <a class="handle" href="http://link-for-non-js-users.html">Content</a> 
    <h3>Medical Variance Reports</h3> 
    <div> 
     <ul> 
      <li><a href="http://mhmssrs2/Reports/Pages/Report.aspx?" target="_blank">Individual Medicines</a></li> 
     </ul> 
    </div> 
</div> 

我怀疑某种程度上pathToTabImage: /images/contact_tab.gif'浏览throught控制器时,失去了它的背景。浏览throught控制器时/images/contact_tab.gif”失去它 方面:帮助我理解......

+0

是否有一个jQuery相当于MVC到@urlcontent? – hidden 2012-03-19 23:17:01

+0

你的图像在哪里搜索?在控制台或“资源”页面中,您应该可以看到图像已被搜索的位置。 – 2012-03-19 23:22:31

回答

2

我怀疑莫名其妙pathToTabImage。

哦,是的,你是对的。处理ASP.NET MVC中的URL时,始终使用url助手:

pathToTabImage: '@Url.Content("~/images/contact_tab.gif")' 

从不像您在代码中那样硬编码urls。这将确保您的应用程序在您将其部署在虚拟目录下的IIS中时工作。

+1

哇我知道你可以使用js里面的@ url.content,这是疯狂的! – hidden 2012-03-20 14:23:27

+0

当我使用@ Url.Content链接说%22/images/report_tab.gif找不到图像我想知道为什么? – hidden 2012-03-20 14:35:18

0

只需使用辅助Url.Content()功能的JS里面像这样

pathToTabImage: @Url.Content("~/images/contact_tab.gif")

如果你的JS是内外部JavaScript文件,你得到的只是指向一个变量,它是全球性的。

在视图的顶部:

变种mypath中= @ Url.Content( “〜/图像/”);

内外部JS文件: pathToTabImage: myPath + "contact_tab.gif"

+0

不适用于我,因为我正在发送该URL路径到处理URL的JavaScript API。 – hidden 2012-03-20 21:32:46

0

这里是我做过什么

alert(UrlContent("/hdd/images.gif")); //for debugging purposes 
alert(UrlContent("~/hdd/images.gif")); 
alert(UrlContent("hdd/images.jpg"); 
//they all return the correct url 

function UrlContent(url) { 



// first lets take care of users that are smart 

url = $.trim(url.replace("~/", "")); //this should take care of smart users! 
if (url.charAt(0) == "/") { 
    url=url.substring(1,url.length) 
} 
//now that we have taken care of smart users lets form the url 

var UrlPath = location.protocol + '//' + location.hostname +location.port+'/'+url 

return UrlPath 

}

+0

我不得不这样做的原因是因为@UrlContent在单独的js文件中没有正常工作。也许有人有更好的答案? – hidden 2012-03-20 16:03:59