简体   繁体   English

在asp.net中加载图片

[英]Loading image in asp.net

EDIT 编辑

I have a upload result action, it can take minutes for returning a new page. 我有一个上传结果操作,返回新页面可能需要几分钟。 I want to set in a div or something a loading image. 我想设置一个div或一个加载图像。

I don't know why but i get the feeling this is not the right way. 我不知道为什么,但是我觉得这不是正确的方法。 What is the right way to show a loading screen/add loading image in ASP.NET. 在ASP.NET中显示加载屏幕/添加加载图像的正确方法是什么。

I have this: 我有这个:

    [HttpPost]
    public ActionResult UploadTarget(UploadViewModel model)
      {
    //code that takes minutes
    return RedirectToAction("UploadSuccess", "Upload");
    }

How can i trigger a function before it begins run the uploadtarget function. 我如何在开始运行uploadtarget函数之前触发一个函数。

<script>
    function wait() {
       document.getElementById("wait").innerHTML = '<img src="/Images/wait.png" alt="Smiley face" height="42" width="42"> ';
    }
</script>

<div class="col-md-6">
     @using (Html.BeginForm("UploadActual", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" })) {
           @Html.AntiForgeryToken()
           @Html.EditorFor(model => model.Remark)
           @Html.ValidationMessageFor(model => model.Remark)
           <input onclick="wait()"type="submit" value="Create" class="btn btn-   primary btn-lg"/>
}
</div>

<div id="wait"class="col-md-6"></div>

It runs my javascript function after the RedirectToaction. 它在RedirectToaction之后运行我的JavaScript函数。 So it does nothing anymore. 因此,它不再执行任何操作。 How can i fix this? 我怎样才能解决这个问题? with c# or javascript? 用C#或JavaScript? Or is there a other good solution? 还是有其他好的解决方案?

You can display the image right away and then submit the form on timeout, to give image time to display. 您可以立即显示图像,然后在超时时提交表单,以使图像有时间显示。 Something like this: 像这样:

function wait() {
   document.getElementById("wait").innerHTML = '<img src="/Images/wait.png" alt="Smiley face" height="42" width="42"> ';
   setTimeout(function(){document.getElementById("myForm").submit()},10);
}

<input onclick="wait()"type="button" value="Create" class="btn btn-   primary btn-lg"/>

Where "myForm" is ID of your form. 其中“ myForm”是表单的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM