如何在我的案例中使这个进度条工作? [英] How can I make this progress bar work in my case?

查看:56
本文介绍了如何在我的案例中使这个进度条工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是关于如何建立进度条的链接,我一直试图让它在我的MVC网站上运行:





https://www.codeproject.com/Articles/1124691/SignalR-Progress-Bar-Simple-Example-Sending-Live-D





问题是当提交按钮与Home控制器中的searchAllQuotes操作绑定时,如何调用StartProcess()?



---------------------------------- ---------------------------------------------

这是我需要在View页面中使用onclick激活进度条的方法:

Below is the link on how to build a progress bar which I have been trying to make it work on my MVC site:


https://www.codeproject.com/Articles/1124691/SignalR-Progress-Bar-Simple-Example-Sending-Live-D


The problem is how do I call "StartProcess()" when the submit button is tied to the action "searchAllQuotes" in the "Home" controller?

-------------------------------------------------------------------------------
This is how I need to activate the progressbar with onclick in the View page:

@using (Html.BeginForm("searchAllQuotes", "Home", FormMethod.Get))
{
<input type="submit" class="btn btn-primary" value="Slideshow of quotes" onclick="StartProcess()"/>
}



以下是您在相同View页面中的javascript:

//控制器中的调用方法可以做一些工作

函数StartProcess(){




Below is your javascript in the same View page:
//CALLING METHOD IN THE CONTROLLER TO DO SOME WORK
function StartProcess() {

$.getJSON("/Home/LongRunningProcess?connectionId=" + connectionId,bindresults),
        {},
        function (data) {
            if (!data) {
                alert("Success");
            }
            else
            {
                alert(data);
            }
        });
    }







-------------- -------------------------------------------------- ----

以下是我的家庭控制器页面:




--------------------------------------------------------------------
Below is my Home controller page:

public ActionResult searchAllQuotes()
{
    return View("~/Views/Quotes/searchQuotes.cshtml", db.Quotes.OrderByDescending(quotes => quotes.DateAdded).ToList());
}

public JsonResult LongRunningProcess(string connectionId)
{
    //THIS COULD BE SOME LIST OF DATA
    int itemsCount = db.Quotes.OrderByDescending(quotes => quotes.DateAdded).ToList().Count;

    for (int i = 0; i <= itemsCount; i++)
    {
        //SIMULATING SOME TASK
        Thread.Sleep(500);

        //CALLING A FUNCTION THAT CALCULATES PERCENTAGE AND SENDS THE DATA TO THE CLIENT
        Functions.SendProgress("Process in progress...", i, itemsCount, connectionId);
    }

    return Json("", JsonRequestBehavior.AllowGet);
}





请注意。在此先感谢。



我尝试过:



同时执行jquery和控制器动作同时但它不起作用。



Please advise. Thanks in advance.

What I have tried:

Executed both jquery and controller action at the same time but it didn't work.

推荐答案

.getJSON( / Home / LongRunningProcess?connectionId = + connectionId,bindresults),
{},
function (数据){
if (!data){
alert( 成功);
}
else
{
alert(data);
}
});
}
.getJSON("/Home/LongRunningProcess?connectionId=" + connectionId,bindresults), {}, function (data) { if (!data) { alert("Success"); } else { alert(data); } }); }







-------------- -------------------------------------------------- ----

以下是我的家庭控制器页面:




--------------------------------------------------------------------
Below is my Home controller page:

public ActionResult searchAllQuotes()
{
    return View("~/Views/Quotes/searchQuotes.cshtml", db.Quotes.OrderByDescending(quotes => quotes.DateAdded).ToList());
}

public JsonResult LongRunningProcess(string connectionId)
{
    //THIS COULD BE SOME LIST OF DATA
    int itemsCount = db.Quotes.OrderByDescending(quotes => quotes.DateAdded).ToList().Count;

    for (int i = 0; i <= itemsCount; i++)
    {
        //SIMULATING SOME TASK
        Thread.Sleep(500);

        //CALLING A FUNCTION THAT CALCULATES PERCENTAGE AND SENDS THE DATA TO THE CLIENT
        Functions.SendProgress("Process in progress...", i, itemsCount, connectionId);
    }

    return Json("", JsonRequestBehavior.AllowGet);
}





请注意。在此先感谢。



我尝试过:



同时执行jquery和控制器动作同时但不起作用。



Please advise. Thanks in advance.

What I have tried:

Executed both jquery and controller action at the same time but it didn't work.


这不会像你尝试的那样工作,只要单击提交按钮,表单就会发布,并且页面会刷新,你需要实现不同的策略,现在还不清楚,你为什么要提交表单并同时调用另一个ajax调用?
This will not work the way you are trying, as soon as the submit button is clicked the form will get post, and page will get refreshed, you need to implement different strategy and it is not clear right now, why are you submitting the form and calling another ajax call simultaneously?


这篇关于如何在我的案例中使这个进度条工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆