[英]ASP.NET Core 3.0: Loading GIF
I'm trying to insert a loading GIF into my project.我正在尝试在我的项目中插入加载 GIF。 I'm using ASP.NET Core 3.0 with Razor Pages, and I understand that I have to use a little bit of Javascript or Ajax to do this.
I'm using ASP.NET Core 3.0 with Razor Pages, and I understand that I have to use a little bit of Javascript or Ajax to do this. I'm new to all of this, so I don't really understand how to implement this, but I've given it a shot.
我对这一切都很陌生,所以我真的不明白如何实现它,但我已经试了一下。 When I load the page, the GIF is there immediately, but the issue is that I only want it to show up when I click my submit button.
当我加载页面时,GIF 会立即出现,但问题是我只想在单击提交按钮时显示它。
This is the code I have for my Upload.cshtml:这是我的 Upload.cshtml 的代码:
@page
@model CustomerPageTest.Pages.Assessment.UploadModel
@{
ViewData["Title"] = "Upload";
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="../Scripts/jquery-1.12.4.js"></script>
<script src="../Scripts/jquery-ui.js"></script>
<script>
$(document).ready(function () {
$('.loadingImage').hide();
$("#buttonSubmit").click(function (event) {
$('.loadingImage').show();
});
});
</script>
<div class="col-md-offset-2 justify-content-center">
<h1 style="color:yellowgreen">3) Import RVTools Spreadsheet (.xls or .xlsx)</h1>
</div>
<br />
<br />
<div class="col-md-offset-3">
<form enctype="multipart/form-data" method="post">
<dl>
<dd>
<input asp-for="@Model.FormFile" type="file" class="text-light">
<span asp-validation-for="@Model.FormFile"></span>
<input asp-for="@Model.CustomerId" type="hidden" />
<span asp-validation-for="@Model.CustomerId"></span>
<input asp-for="@Model.AssessmentId" type="hidden" />
<span asp-validation-for="@Model.AssessmentId"></span>
</dd>
<dd>
<img id="loadingImage" src="~/css/Images/ajax-loader.gif" alt="Loading ..." style="display: none;" />
</dd>
</dl>
<dl>
<dd>
<button id="buttonSubmit" asp-page-handler="Upload" class="btn btn-dark" type="submit">Upload File</button>
</dd>
</dl>
</form>
</div>
When I run the program and don't click Upload File, this is what I get:当我运行程序并且不单击上传文件时,这就是我得到的:
How can I make this GIF only appear when I hit Upload File?我怎样才能让这个 GIF 只在我点击上传文件时出现? The program goes to the OnPost() function when I click 'Upload File' because it has to run a large algorithm with the given file and I want the GIF there for when that program runs.
当我单击“上传文件”时,该程序转到 OnPost() function,因为它必须使用给定文件运行一个大型算法,并且我想要该程序运行时的 GIF。
Your jquery script targets a class loadingImage but the element has that as id.您的 jquery 脚本以 class loadingImage 为目标,但该元素将其作为 id。 Use $('#loadingImage') instead.
改用 $('#loadingImage') 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.