There is an asynchronous method

ReportController.cs

public async Task<ActionResult> GetRMschools() { Account account = new Account("chr_coko.pto@mail.ru", "***"); var api = new MailRuCloud(); api.Account = account; string schoolID = User.Identity.Name; var items = await api.GetItems($@"/Reports/{schoolID}"); school school_current = schoolRepository.GetT(schoolID); List<RMschool> model = new List<RMschool>(); foreach (var file_name in items.Files) //eg file_name = "0001_201636.zip" { int report_code = Convert.ToInt32(file_name.Name.Substring(5, 6)); //eg report_code = 201636 var ob = monit95Context.ReportMetas.Find(report_code); model.Add(new RMschool { code = ob.code, name = ob.name, ProjectName = ob.ProjectName, year = ob.year, WWWref = $@"{school_current.ReportLink}/{file_name.Name}" }); } return PartialView("_GetRMschools", model); 

which causes a partial view

_GetRMschools.cshtml

 @using Monit95App.Models @model List<RMschool> <body> <table class="table"> <thead class="thead-inverse"> <tr> <th>Проект</th> <th>Отчет</th> <th>Учебный год</th> </tr> </thead> @foreach (var reportMeta in Model.OrderByDescending(x => x.code)) { <tr> <td>@reportMeta.ProjectName</td> <td><a href="@reportMeta.WWWref">@reportMeta.name</a></td> <td>@reportMeta.year</td> </tr> } </table> </body> 

Now I am trying to get this partial view in another View.

Report.cshtml

 <h2>Отчеты</h2> @Html.Action("GetRMschools") 

When running, displays:

Error executing child request for descriptor 'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'

HttpServerUtility.Execute is blocked until the end of the asynchronous operation.

  1. Why it happens?
  2. How to fix?
  • make the Action which returns PartialView normal (without async await) let's see what happens - Ruslan_K
  • @Ruslan_K unfortunately this is not an option - the MailCloud API is written on asynchronous calls. I initially tried to do so. - Adam
  • for the test, you can check for var items = api.GetItems($@"/Reports/{schoolID}").Result; - Ruslan_K
  • @Ruslan_K I did this: on this line, my program hangs up - it leaves me as if I’ve gotten to sleep. - Adam
  • understandable, well, let's wait for what the more experienced participants of SO will say :) - Ruslan_K

1 answer 1

The reason for which everything did not work: if the action контроллера is called from View , then such a call is considered a дочерним . And in ASP.NET MVC 5 child methods cannot be called асинхронно . In ASP.NET Core everything seems to be somehow different, as far as I understood correctly.

The complexity of the task for me is that: I need to call a partial representation of _RMschool.cshtml on different pages of my application, and I have it типизированное . And so before calling it (_RMschool.cshtml), you still need to get a model for it.

The decision . Found an article on the Internet and with its help out of the situation:

ReportController.cs

 [HttpGet] public async Task<ActionResult> Report() { var model = await GetRMschoolList(User.Identity.Name); return PartialView("_RMschool", model); } public async Task<ActionResult> GetRMschoolPV(string _schoolID) { var model = await this.GetRMschoolList(_schoolID); return PartialView("_RMschool", model); } public async Task<List<RMschool>> GetRMschoolList(string _schoolID) //GetViewModel { Account account = new Account("chr_coko.pto@mail.ru", "***"); var api = new MailRuCloud(); api.Account = account; var items = await api.GetItems($@"/Reports/{_schoolID}"); school school_current = schoolRepository.GetT(_schoolID); List<RMschool> model = new List<RMschool>(); //du stuff return (model); } 

Report.cshtml

 @model IEnumerable<Monit95App.Models.RMschool> @{ Html.RenderPartial("_RMschool", Model);} 

_RMschool.cshtml

 @model IEnumerable<Monit95App.Models.RMschool> <body> <table class="table"> <thead class="thead-inverse"> <tr> <th>Проект</th> <th>Отчет</th> <th>Учебный год</th> </tr> </thead> @foreach (var reportMeta in Model.OrderByDescending(x => x.code)) { <tr> <td>@reportMeta.ProjectName</td> <td><a href="@reportMeta.WWWref">@reportMeta.name</a></td> <td>@reportMeta.year</td> </tr> } </table> </body> 
  • Too difficult to work out. It looks like you don't need two different views. - Pavel Mayorov
  • one
    In addition, what happened and why was not explained. - Pavel Mayorov
  • @PavelMayorov Thanks for the comment about not specifying the reason . The answer is edited. - Adam
  • @PavelMayorov about It looks like you do not need two different View . Did not quite understand the remark. Can you say more? - Adam
  • one
    You Report.cshtml used only to enable _RMschool.cshtml . It was possible to immediately display the second file. - Pavel Mayorov