我认为我可以拖放从我内容的文件夹,自动获得图片地址。
<div style="text-align:center">
<img src="~/Content/information-button16.png" id="info-@car.Car_ID" />
<img src="~/Content/center-icon.png" id="center-@car.Car_ID" />
</div>
现在我试着去创建一个块消息并且想要添加等待光标,但这似乎并不工作,因为内容不是公用文件夹。
$('#tabs').block({
message: '<h1><img src='
+ localpath
+ '@Url.Content("/GTracker/Content/busy.gif")'
+ ' /> Just a moment...</h1>',
css: { border: '2px solid #3399ff' }
});
我该怎么办?
似乎无法找到一个快速的参考,但 ~
可用于 <img src='~/...
和 @Url.Content("~
。 它不会在 js 文字工作。
如果你的 js 是Razor.cshtml,你可以︰
$('#tabs').block({
message: '<h1><img src='
+ '"'
+ '@Url.Content("~/GTracker/Content/busy.gif")'
+ '"'
+ ' /> Just a moment...</h1>',
css: { border: '2px solid #3399ff' }
});
或
$('#tabs').block({
message: '<h1><img src="@Url.Content("~/GTracker/Content/busy.gif")" /> Just a moment...</h1>',
css: { border: '2px solid #3399ff' }
});
如果相反,此代码是在.js 文件中,您需要通过在转换的根路径的东西一样,在 _layout.cshtml 通常这样︰
<head>
<script>var rootpath = '@Url.Content("~")';</script>
然后您可以使用 rootpath 在你.js (假设它已包括在上述后)
$('#tabs').block({
message: '<h1><img src='
+ '"'
+ rootpath + '/Content/busy.gif'
+ '"'
+ ' /> Just a moment...</h1>',
css: { border: '2px solid #3399ff' }
});
Aleviates 硬编码路径,并允许您的网站移动左右的要求。