我正在使用MVC C#Razor Framework 4.6。使用任务运行(异步)响应中的部分视图更新UI
我有静态方法ExportManager.ExportExcelCannedReportPPR
包装在Task.Run
长期运行的报告。此方法返回boolean
值并基于此我刷新部分视图(_NotificationPanel
)。
public ActionResult ExportCannedReport(string cannedReportKey, string cannedReportName)
{
string memberKeys = _curUser.SecurityInfo.AccessibleFacilities_MemberKeys; //ToDo: Make sure this is fine or need to pass just self member?
string memberIds = _curUser.SecurityInfo.AccessibleFacilities_MemberIDs; //ToDo: Make sure this is fine or need to pass just self member?
string curMemberNameFormatted = _curUser.FacilityInfo.FacilityName.Replace(" ", string.Empty);
string cannedReportNameFormatted = cannedReportName.Replace(" ", string.Empty);
string fileName = string.Concat(cannedReportNameFormatted, "_", DateTime.Now.ToString("yyyyMMdd"), "_", curMemberNameFormatted);
//ToDo: Make sure below getting userId is correct
string userId = ((_curUser.IsECRIStaff.HasValue && _curUser.IsECRIStaff.Value) ? _curUser.MembersiteUsername : _curUser.PGUserName);
var returnTask = Task.Run<bool>(() => ExportManager.ExportExcelCannedReportPPR(cannedReportKey, cannedReportName, fileName, memberIds, userId));
returnTask.ContinueWith((antecedent) =>
{
if (antecedent.Result == true)
{
return PartialView("_NotificationPanel", "New file(s) added in 'Download Manager'.");
}
else
{
return PartialView("_NotificationPanel", "An error occurred while generating the report.");
}
}, TaskContinuationOptions.OnlyOnRanToCompletion);
return PartialView("_NotificationPanel", "");
}
现在的问题是,即使在_NotificationPanel
得到ContinueWith
执行UI没能刷新。
你真的希望在该代码中发生什么? –