2021年3月31日星期三

ASP.NET MVC. How to return View with Model produced by asyncronous function

I have function produced Model asynchronously, function working fine.

        Async Function ReadLocations(Skip As Integer) As Task(Of Model.ViewLocation)              ...              Return Await Task.Run(Function() Model)          End Function  

I creating an async controller using this Model and may be confused with the right syntax to load the Async model to View. Where is the right place for Await? And what right way to create a reference to async delegate who will create a model - Task.FromResult or Task.Result?

       Public Async Function Index(id as integer) As Task(Of ActionResult)              ...              If UserState IsNot Nothing Then                   Dim Model As Model.ViewLocation = Await Task.Run(Function() ReadLocations(id))                   Dim ModelTask As Task(Of Model.ViewLocation) = ReadLocations(id)                   '--------                   Return ???  View("Index", Await Model/ModelTask)  ???                   or                    Return Await ??? Task.Run(Function() View("Index", Model/ModelTask)) ???                   '--------              Else                  Return Await Task.Run(Function() RedirectToAction("Index", "Home"))              End If          End Function  
https://stackoverflow.com/questions/66896307/asp-net-mvc-how-to-return-view-with-model-produced-by-asyncronous-function April 01, 2021 at 06:52AM

没有评论:

发表评论