Asp.net mvc ASP.Net核心MVC块重定向中的数据ajax开始脚本

Asp.net mvc ASP.Net核心MVC块重定向中的数据ajax开始脚本,asp.net-mvc,asp.net-core,asp.net-ajax,Asp.net Mvc,Asp.net Core,Asp.net Ajax,我试图在ASP.NET内核中创建一个简单的微调器,它将在长时间控制器运行时显示 代码按预期工作,但似乎阻止了控制器操作中的重定向。 有没有办法让重定向在这种情况下工作 My Index.cshtml <script src="~/lib/jquery/dist/jquery.min.js"></script> <script src="~/lib/jquery-ajax-unobtrusive/src/jquery.unobtrusive-ajax.js">&

我试图在ASP.NET内核中创建一个简单的微调器,它将在长时间控制器运行时显示

代码按预期工作,但似乎阻止了控制器操作中的重定向。 有没有办法让重定向在这种情况下工作

My Index.cshtml

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/jquery-ajax-unobtrusive/src/jquery.unobtrusive-ajax.js"></script>

<script type="text/javascript">
    function onBegin() {
        $("#divLoading").html('<image src="~/images/ajax-loader.gif" alt="Loading, please wait" />');
    }
    function onComplete() {
        $("#divLoading").html("");
    }
</script>

<form data-ajax="true" data-ajax-begin="onBegin" data-ajax-complete="onComplete" asp-action="LoadLongLasting" asp-controller="Home">
    <input type="submit" value="Load Long lasting"/>
</form>
<div id="divLoading"></div>

您需要像这样在onSuccess函数中返回json并写入重定向

视图:


ajax的全部目的是保持在同一页面上。Ajax调用从不重定向,因此
返回RedirectToAction(“错误”)
是无点的,那么在请求开始时显示一个已实现的微调器并在请求结束时隐藏而不使用Ajax的最佳实践是什么呢。我相信这是一个相当普遍的情况,但老实说,我不知道。
    public ActionResult LoadLongLasting()
    {
        bool result = GetLongLastingResult();

        if(result)
        {
            return View();
        }

        return RedirectToAction("Error");
    }
<script type="text/javascript">
    function onBegin() {
        $("#divLoading").html('<image src="~/images/ajax-loader.gif"
alt="Loading, please wait" />');
    }
    function onSuccess() {
        if(data.status === 1) {
            window.location.href = "/yourpage";
        }
    }
    function onComplete() {
        $("#divLoading").html("");
    }
</script>

<form data-ajax="true" data-ajax-begin="onBegin" data-ajax-complete="onComplete" data-ajax-success="onSuccess" asp-action="LoadLongLasting" asp-controller="Home">
    <input type="submit" value="Load Long lasting"/>
</form>
public ActionResult LoadLongLasting()
{
    bool result = GetLongLastingResult();

    if(result)
    {
        return View();
    }
    return Json(new { status = 1 });
    //return RedirectToAction("Error");
}