url.content(...),如jQuery中或javascript的方法? [英] url.content(...) like method in jquery or javascript?
问题描述
可能重复:结果
在Java脚本 URL助手
Url.Content(...)asp.net的MVC辅助方法返回相当于绝对URL。我在寻找jQuery中或JavaScript方法,它是这样的...
Url.Content(...) asp.net mvc helper method returns equivalent absolute URL. I'm searching for a method in jquery or javascript that works like this...
因为,我要分隔符的JavaScript code到一个文件中(.js文件),你知道,文件不支持Url.Content(...)javscript code里面....
because, I want to separat javascript code into a file (.js) and you know that file doesn't supports Url.Content(...) inside javscript code....
URL(...)的jQuery的方法不是就像Url.Content()
url(...) method of jquery not works like Url.Content()
更新时间:2011年1月22日
家伙我有一个解决方法:
Hi guys, I’ve a workaround:
在.cshtml文件,我创建了一个'的getPath '函数返回的绝对路径,包括域名,可以是内部的任何.js文件访问。
包括下列任何ASP.NET MVC视图code(.cshtml或的.aspx或.vbhtml):
In the .cshtml file, I created a ‘GetPath’ function that returns absolute path including domain name and can be accessible inside any .js file. Include following code in any ASP.NET MVC view (.cshtml or .aspx or .vbhtml):
<script type="text/javascript">
var fullPath = '@HttpContext.Current.Request.Url.Scheme://@HttpContext.Current.Request.Url.Authority';
function GetPath(url) {
return fullPath + url;
}
</script>
<script src="@Url.Content("~/JavaScriptFile.js")" type="text/javascript"></script>
和任何JavaScript文件中的code。
And the code inside any javascript file.
$(function () {
alert(GetPath('/Content/Site.css'));
});
结果是: http://www.yourDomain.com/Content/Site.css
或本地主机:1234 /内容/的site.css >>视觉卡西尼服务器
The result is: http://www.yourDomain.com/Content/Site.css or localhost:1234/Content/Site.css >> Visual Cassini server
您只需要更换 @ Url.Content()
与的getPath('')
中的任何.js文件...
You just need to replace @Url.Content("")
with GetPath('')
in any .js file...
<一个href=\"http://muaz-khan.blogspot.com/2012/02/absolute-or-relative-url-issues-and.html\">http://muaz-khan.blogspot.com/2012/02/absolute-or-relative-url-issues-and.html
推荐答案
有一个看的 ASP.NET MVC的JavaScript路由
这篇关于url.content(...),如jQuery中或javascript的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!