仅继承母版页中的 javascript 代码
所以我的母版页上有一个 Javascript 函数。当我从从此母版页派生的页面调用它时,它工作正常,但是,在不派生的页面上,它显然不起作用。我无法将其放入另一个 .js 文件中,因为它使用了一些嵌入的 C# 代码,因此它必须位于 标记内。
这就是函数:
function GridExport(viewUrl, fileName)
{
var actionUrl = "<%= System.Web.VirtualPathUtility.ToAbsolute("~/mvc/Indications.cfc/ExportToExcel")%>";
var guid = GetGUIDValue();
window.open((actionUrl + "?id=" + guid + "&viewName=" + viewUrl + "&fileName=" + fileName), null, null, null);
}
有没有一种方法可以将我的母版页中的 Javascript 定义包含在另一个视图中,而不从母版页派生?
So I have a Javascript function on my master page. It works fine when I call it from pages that derive from this master page, however, on pages that don't, it obviously doesn't work. I am not able to put it in another .js file either because it uses some embedded c# code in it, so it has to be within a <script>
tag.
This is the function:
function GridExport(viewUrl, fileName)
{
var actionUrl = "<%= System.Web.VirtualPathUtility.ToAbsolute("~/mvc/Indications.cfc/ExportToExcel")%>";
var guid = GetGUIDValue();
window.open((actionUrl + "?id=" + guid + "&viewName=" + viewUrl + "&fileName=" + fileName), null, null, null);
}
is there a way I can just include the Javascript definitions from my master page in another view without deriving from the master page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个包含此
的
UserControl
或将actionUrl
抽象为GridExport
的参数function避免此路径问题的另一个简便方法是使用一个全局变量来定义站点的根:
然后您的函数可以始终使用此变量并附加它需要的内容:
You could create a
UserControl
containing this<script>
or abstract out theactionUrl
to a parameter of theGridExport
functionAnother handy way to avoid this path problem would be to have a global variable to define the root of the site:
then your function could always use this variable and append what it needs:
母版页可以相互嵌入。为什么不直接制作一个只包含 javascript 的母版页呢?然后制作另一个以 javascript 母版页作为母版页的母版页。创建新页面时,您可以选择使用哪一个页面。
MasterPage1 ->只是 javascript
MasterPage2 ->包含您的其他内容,并以 MasterPage1 作为其主控。
如果您只需要 javascript,则用户使用 MasterPage1,对于其他所有内容,用户使用 MasterPage2。
Master pages can be embedded within each other. Why not just make a master page with only your javascript in it. Then make another master page that has the javascript master page as it's master. When creating new pages you can choose which one to use.
MasterPage1 -> Just javascript
MasterPage2 -> Contains your other stuff and has MasterPage1 as it's master
If you just want the javascript then user MasterPage1, for everything else user MasterPage2.