Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone,

How would I change my set of code to asynchronous?

Here's my code:
C#
public class ReportController : Controller
    {
        //
        // GET: /Report/
        //*** Daily Sales Report (Summary)
        public ActionResult DailySalesReport()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult GetDailySalesReport(String date)
        {
            CommReportManager commReportManager = new CommReportManager();
            var dailySalesReport = commReportManager.GetDailySalesReport(date);
            return Json(dailySalesReport);
        }
}


Thank You very much for your time.
Posted

1 solution

Try this

XML
public async Task<ActionResult> GetDailySalesReport(String date)
{
    ViewBag.SyncOrAsync = "Asynchronous";
    var gizmoService = new GizmoService();
    return View("Gizmos", await gizmoService.GetGizmosAsync());

    CommReportManager commReportManager = new CommReportManager();
    var dailySalesReport = commReportManager.GetDailySalesReport(date);
    return await Json(dailySalesReport);

}
 
Share this answer
 
Comments
Nu Sij 30-Jul-14 13:27pm    
Hi @Kumarbs, thank you so much, but I can't find the 'async' keyword. I am actually using MVC4 in Visual Studio 2010 and the .Net framework is 4.0.
Kumarbs 31-Jul-14 0:49am    
Well, Async calls introduced in MVC4 itself, if you are not finding means, you are using prior versions. Alternatively you can use ajax calls in jquery.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900