文件上传完成后调用jquery脚本asp.net mvc 2

发布于 2024-11-06 00:19:44 字数 736 浏览 1 评论 0原文

我试图在文件上传操作后显示 jquery 弹出窗口?不确定如何编码?

 <%= Html.BeginForm("Upload","Home",FormMethod.Post,new { enctype = "multipart/form-data" }) %>
<%{ %>


<input type="file" id="upload" name="upload" />

<button id="btnUpload">
    upload</button>



<%} %>

 <script type="text/javascript">

    function SayFinished() {
        alert('Finished');
    }
 </script>

[HttpPost]
    public ActionResult Upload()
    {
        HttpPostedFileBase selectedFile = Request.Files["upload"];

        if (selectedFile.ContentLength > 0 )
        {
            //do some processing call jquery script to open popup: SayFinished()
        }

        return View("Index");
    }

i am trying to display a jquery popup after a fileupload action? not sure how to code this?

 <%= Html.BeginForm("Upload","Home",FormMethod.Post,new { enctype = "multipart/form-data" }) %>
<%{ %>


<input type="file" id="upload" name="upload" />

<button id="btnUpload">
    upload</button>



<%} %>

 <script type="text/javascript">

    function SayFinished() {
        alert('Finished');
    }
 </script>

[HttpPost]
    public ActionResult Upload()
    {
        HttpPostedFileBase selectedFile = Request.Files["upload"];

        if (selectedFile.ContentLength > 0 )
        {
            //do some processing call jquery script to open popup: SayFinished()
        }

        return View("Index");
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

林空鹿饮溪 2024-11-13 00:19:44

最简单的方法是在具有 onload 脚本的帖子之后从控制器返回一个视图。

在新视图上,放置以下 javascript:

在文件上传后在控制器中设置以下内容

ViewData["FileUploaded"] = "true";

然后在视图中设置

<% if (!String.IsnullOrEmpty(ViewData["FileUploaded"]) && ViewData["FileUploaded"] == "true") { %>
     <script type="text/javascript">
        $(document).ready(function() {
            SayFinished();
        });

        function SayFinished() {
            alert('Finished');
        }
     </script>
<%} %>

The simplest way to do this is to return a view from your controller after the post that has an onload script.

On the new view, put the following javascript:

In the controller set the following after file uploaded

ViewData["FileUploaded"] = "true";

Then in the view set

<% if (!String.IsnullOrEmpty(ViewData["FileUploaded"]) && ViewData["FileUploaded"] == "true") { %>
     <script type="text/javascript">
        $(document).ready(function() {
            SayFinished();
        });

        function SayFinished() {
            alert('Finished');
        }
     </script>
<%} %>
清秋悲枫 2024-11-13 00:19:44

您可以使用此插件使用 jQuery 上传文件, http://pixelcone.com/jquery /ajax-file-upload-script

对于之前的反馈信息不正确,我们深表歉意。

You can use this plugins to upload file using jQuery, http://pixelcone.com/jquery/ajax-file-upload-script

Sorry for previous feedback with incorrect information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文