Home » Jquery » c# – How to bind to events on the server and display their effect-Exceptionshub

c# – How to bind to events on the server and display their effect-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I am writing a small project on ASP.Net Core
I faced the following situation and at the moment I do not quite understand how I can connect the execution of some actions with the visual loader.
I have the following controller code in which asynchronous data upload starts:

public async Task<IActionResult> OnPostAsync(string email)
{
    int count = 0;

    await foreach (var item in _transferService.TransferAsync(email, serialNums))
    {
        var toFrontObj = new ToFrontLoadItem
        {
           Count = ++count,
           Serial = item.RespObj as string,
           Message = item.ErrorMessage
        }
    }
   // so far I'm just returning to the page
    return RedirectToPage("/Index", new { area = "Workspace" });
}

   public async IAsyncEnumerable<InterlayerResponse> TransferAsync(string email, List<string> serialNums)
    {
        foreach (string serialNum in serialNums)
        {
            var bchAnsw = await _blokchain.TransferAsync(new FromViewTransferDTO
            {
                DestinationEmail = email,
                SerialNumber = serialNum,
                AuthToken = _session.User.AuthToken
            });
            if (bchAnsw.Status == SUCCESS) yield return new InterlayerResponse
            {
                Successful = true,
                RespObj = serialNum
            };
            else yield return new InterlayerResponse
            {
                Successful = false,
                RespObj = serialNum,
                ErrorMessage = bchAnsw.Reason
            };
        }
    }

For visualization, I use a third-party solution, the essence of which is to get an answer after each iteration and process it with a script

$("#_trasfer_progress").data("kendoProgressBar").value({COUNT from server})

Tell me a working solution in such situations.

How to&Answer: