Home get counter value int from method that return a bool and return to browser
Reply: 0

get counter value int from method that return a bool and return to browser

user1649
1#
user1649 Published in July 20, 2018, 1:20 am

I'm trying to work out how I can get the value of a counter in a method that is inside a foreach loop.

I have thought about delegates but I cannot work out how to do that.

My method is with all irreverent code removed

public static bool ReadExcelFile(string str1, int Id, out int tCount)
{
    int primaryCounter = 0;                    

    //Insert new items
    foreach (var item in excelList)
    {                
        primaryCounter++;                                
    }

    return true;
}                

I then have a ActionResults which I use for the jquery polling

public ActionResult InsertPolling()
{
    int currentCount = //How to get value of counter        
    string pollingMessage = $"Inserted {currentCount}  items";
    return Json(pollingMessage, JsonRequestBehavior.AllowGet);
}

My jQuery is:

function doPollHandler(event) {
    $.post('/UploadData/InsertPolling',
        function(data) {
            alert(data); // process results here
            setTimeout(window.doPollHandler, 2000);
        });
};

$('#fileUpload').change(function () {
    doPollHandler();
});

I have looked at https://www.tutorialspoint.com/csharp/csharp_delegates.htm

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/using-delegates

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/how-to-declare-instantiate-and-use-a-delegate

But as my method returns a bool, and I need to get the value of counter I'm stuck on how to do this.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309023 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO