如何从javascript工作在c# .aspx文件,指向正确的文件夹/文件与href和src

How to get functions from a javascript working in c# .aspx file, pointing to the right folder/file with href and src

本文关键字:文件 文件夹 src href javascript 工作 aspx      更新时间:2023-09-26

我有一个。aspx文件,我想在其中有一个文件上传器,我从这里得到的。有一些例子包括如何使其工作。当我测试它只做HTML和javascript,我可以让它工作,但当我试图让它与c#工作,我不能得到路径到。js文件的权利。

示例html/javascript文件如下:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="fileuploader.css" rel="stylesheet" type="text/css"> 
    <style>     
        body {font-size:13px; font-family:arial, sans-serif; width:700px; margin:100px auto;}
    </style>    
</head>    
    <script src="fileuploader.js" type="text/javascript"></script>
    <script>        
        function createUploader(){            
            var uploader = new qq.FileUploader({
                element: document.getElementById('file-uploader-demo1'),
                action: 'do-nothing.htm',
                debug: true
            });           
        }
        // in your app create uploader as soon as the DOM is ready
        // don't wait for the window to load  
        window.onload = createUploader;     
    </script>    
</body>
</html>

我想在下面的。aspx文件中得到它。.js和.css文件位于D:'svn'Web'Framework'Trunk'test.Web。Framework'Scripts'fileuploader的位置和。aspx文件位于D:'svn'Web'Healthcare'trunk'test.Web.Healthcare'Areas'Framework'Administration'Entity。我尝试做以下操作,但这给了我一个GET =1325724928825">http://localhost:1304/Administration/blue/en-gb/Entity/Index/~/Scripts/fileuploader/fileuploader.js?=1325724928825 404 (Not Found)错误:

<%@ Control Language="C#" Inherits="test.Web.Framework.Core.ViewUserControl<test.Web.Framework.Areas.Administration.Models.NoteModel>" %>
<% using (UI.koform(Model, null))
{ %>
    <div class="ui-state-highlight ui-corner-all highlight" data-bind="visible: meta.message">
        <span class="ui-icon ui-icon-info"></span><strong data-bind="text: meta.message">
        </strong>
    </div>
    Subject:
    <input type="text" data-bind="value:subject" />
    <span data-bind="text: subject"></span>
    <br />
    Text:
    <input type="text" data-bind="value:text" />
    <br />
    <!--
    <a href="#" data-bind="click:function(){setvalues() }">set values</a>
-->
    <div class="dialogButtons">
        <button onclick="$('#<%:Model.meta.modelname%>').koform('submit');">
            Save</button>
    </div>

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="~/Scripts/fileuploader/fileuploader.css" rel="stylesheet" type="text/css">  
    </head>
    <div id="file-uploader-demo1">      
        <noscript>          
            <p>Please enable JavaScript to use file uploader.</p>
            <!-- or put a simple form for upload here -->
        </noscript>         
    </div>
    "~/Scripts/fileuploader/fileuploader.css"
    <script src="~/Scripts/fileuploader/fileuploader.js" type="text/javascript"></script>
    <script>        
            function createUploader() {
                var uploader = new qq.FileUploader({
                    element: document.getElementById('file-uploader-demo1'),
                    action: 'do-nothing.htm',
                    debug: true
                });
            }
            // in your app create uploader as soon as the DOM is ready
            // don't wait for the window to load  
            window.onload = createUploader;     
        </script>    
<%}%>

很容易修复。用这样的东西替换你的文件…

<script src="<%=ResolveClientUrl("~/Scripts/fileuploader/fileuploader.js")%>" type="text/javascript"></script>

这将解析相对于你的web应用程序的根文件夹的URL。对样式表和其他引用执行同样的操作。

我经常使用这个,尤其是在母版页中。