Good afternoon, dear members of the forum, I will go straight to the heart of the problem. There is a view, inside of which there is a div block, where I display the result of PartialView . Here’s what the View looks like:

 @using (Ajax.BeginForm(T4.Admin.PlanningInformationImport(), new AjaxOptions{ HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "planning-import-history-block", OnBegin = "AjaxAbsoluteLoaderOn", OnComplete = "AjaxAbsoluteLoaderOff" }, new { @class = "form-horizontal", enctype = "multipart/form-data" })) { <div class="control-group"> <label class="control-label">Дата</label> <div class="controls"> <input type="text" id="filter-date" name="filterDate" value="@Model.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture)" /> </div> </div> <fieldset> <legend>Заливка домов</legend> <div class="control-group"> <label class="control-label">Файл</label> <div class="controls"> <input id="import-file" type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" name="fileUpload" /> </div> </div> </fieldset> <div class="control-group"> <div class="controls"> <button id="downloadPremises" class="btn btn-success" type="submit" >Загрузить дома</button> </div> </div> } <fieldset> <legend>История</legend> <div class="row" id="planning-import-history-block"> </div> </fieldset> 

Nothing innocuous, it's simple. Here is the controller's method that changes PartialView returns to me:

 [HttpPost] public virtual PartialViewResult PlanningInformationImport(HttpPostedFileBase fileUpload, DateTime filterDate, FormCollection formData) { string message = null; if (fileUpload != null) { using (var stream = new MemoryStream()) { fileUpload.InputStream.CopyTo(stream); _buildingService.ImportPlanningInformationsAsync(stream.ToArray(), fileUpload.FileName); message = "Загрузка файла началась"; } } return PartialView(T4.Admin.Views._PlanningInformationImportHistoryPartial, PreparePlanningInformationImporHistoryModel(filterDate, message)); } private PlanningInformationImportHistoryModel PreparePlanningInformationImporHistoryModel(DateTime filterDate, string message) { var model = new PlanningInformationImportHistoryModel(); model.ImportStartedMessage = message; model.Imports = _buildingService.GetPlanningImports(filterDate).Result; return model; } 

We see that the controller returns a _PlanningInformationImportHistoryPartial , which looks like this:

 @model ibZKH.Web.Models.Admin.PlanningInformationImportHistoryModel @if (Model.ImportStartedMessage != null) { <div class="alert alert-success"> <button type="button" class="close" data-dismiss="alert">&times;</button> <strong>@Model.ImportStartedMessage</strong> </div> } <div class="span10"> @if (Model.Imports.Length > 0) { <table class="table table-bordered table-striped table-condensed"> <thead> <tr> <td>Документ</td> <td>Дата заливки</td> <td>Статус</td> <td></td> <td></td> </tr> </thead> <tbody> @for (var i = 0; i < Model.Imports.Length; i++) { <tr> <td>@Model.Imports[i].FileName</td> <td> @Model.Imports[i].ImportTime.ToShortDateString() </td> <td> @Model.Imports[i].Status </td> <td> <a href="@Url.Action(T4.Admin.DownloadPlanningInformationImportReport(Model.Imports[i].Id, Model.Imports[i].FileName))" title="Отчет о загрузке"> <i class="icon-download"></i> </a> </td> <td> <a href="@Url.Action(T4.Admin.DownloadPlanningInformationImportErrors(Model.Imports[i].Id, Model.Imports[i].FileName))" title="Детальный отчет об ошибках"> <i class="icon-download-alt"></i> </a> </td> </tr> } </tbody> </table> } else { <span class="label label-default"> В выбранный день не было произведено импорта помещений </span> } </div> 

If you put a breakpoint, then everything is done correctly, as it should be. Everything is filled, and everything is displayed, but !

The result of this operation is displayed in 2-3 minutes!

On all other views that are in this model (and in any other) - everything is displayed quickly, almost instantly. But this view has a strange glitch. Why is this happening and how to solve this problem?

    1 answer 1

    most likely a problem in the line

     model.Imports = _buildingService.GetPlanningImports(filterDate).Result; 

    Do you have this page rendered somewhere as a separate block? If it is used only for this Ajax request, make ParvialViewResult a full-fledged async Task "ActionResult" and use await in this operation.

    • the GetPlanningImports method works in a split second, almost instantly. Or speed does not affect? - Denis Bubnov
    • Try to comment out the line for testing, will it be faster after that? In general, partial views in Asp.net mvc 5 do not involve the use of asynchronous methods. - Fakemind
    • @DenisBubnov problem is that it starts an asynchronous operation. And getting Result makes you wait for it to finish. - Pavel Mayorov
    • @PavelMayorov, did not help. I did what you said and replaced it with the following line: model.Imports = new PremiseImportResultDto[0]; It still works for a long time. - Denis Bubnov
    • @DenisBubnov and what size file do you download? - Pavel Mayorov