简体   繁体   English

ASP.NET Core 3.0:加载 GIF

[英]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.

相关问题 ASP.NET Core 3.0:当 OnPost() 被命中时显示 GIF - ASP.NET Core 3.0: Display GIF when OnPost() gets hit SignalR和ASP.NET核心页面未加载 - SignalR and ASP.NET core page not loading ASP.NET Core:加载Java依赖项时出现问题 - ASP.NET Core: Problems loading dependencies of Javascript 防止在Asp.Net Core ViewComponents中加载多个JavaScript脚本 - Preventing multiple JavaScript scripts loading in Asp.Net Core ViewComponents 在 ASP.NET Core MVC 中将数据加载到 Bootstrap Dual Listbox - Loading data into Bootstrap Dual Listbox in ASP.NET Core MVC 我可以在Asp.NET MVC 4中使用异步加载节点获得一个有效的jsTree 3.0示例吗? - Can I get a working jsTree 3.0 example in Asp.NET MVC 4 with async loading of nodes? 如何使用另一个下拉列表 asp.net core 3.0 过滤下拉列表的选项 - How to filter the options of a drop down list using another drop down list asp.net core 3.0 使用 ASP.Net Core SDK 3.0 preview8(Blazor 框架)上传图像 - Uploading image using ASP.Net Core SDK 3.0 preview8 (Blazor framework) 如何使用react js和asp.net core v3.0下载文件 - How to download file using react js and asp.net core v3.0 ASP.NET Core 3.0 MVC 连接中的 SignalR 无法正常工作? - SignalR in ASP.NET Core 3.0 MVC connection keep alive not working?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM