MvcCorePager
MvcCorePager copied to clipboard
.net core 3.0中Html.Pager输出问题
在页面中使用Html.Pager(...)时,该页面在浏览器输出的html内容被截断,查看服务器日志显示“ Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.”
有一种折中的解决办法是设置应用程序允许输出同步流,详情见:https://github.com/aspnet/AspNetCore/issues/8302, https://github.com/aspnet/AspNetCore/issues/7644。
您好,您有简单的演示示例传上来或发我看一下吗?以前没见过这种情况,是.net core 3.0特有的问题吗?谢谢!
也碰到了这个问题,您那个是怎么解决的啊,链接打不开了
我新建Mvc Core 3.0的MvcCorePager测试项目,没有发现有什么错误,请问怎么能重现你们所说的问题?谢谢!
项目的目标框架是:.NET Core 3.0 示例代码如下
controller代码
using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc;
using AspNetCorePage;
namespace WebApp04.Controllers { public class HomeController : Controller { public async Task<IActionResult> List() { var list = Enumerable.Range(1, 10);
return View(new PagedList<int>(list, 1, 1, 10));
}
}
}
view代码
@using AspNetCorePage
@model PagedList
@foreach (var item in Model) { @(item) }
@Html.Pager(Model, new PagerOptions { NumericPagerItemCount = 8, PageIndexParameterName = "page", TagName = "ul", CssClass = "pagination", CurrentPagerItemTemplate = "<li class="page-item active"><a class="page-link" href="javascript:void(0)">{0}", DisabledPagerItemTemplate = "<li class="page-item disabled"><a class="page-link " href="javascript:void(0)">{0}", PagerItemTemplate = "<li class="page-item page-link ">{0}", Id = "bootstrappager" })
页面异常内容
System.InvalidOperationException: Synchronous operations are disallowed. Call WriteAsync or set AllowSynchronousIO to true instead.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at Microsoft.AspNetCore.WebUtilities.HttpResponseStreamWriter.FlushInternal(Boolean flushEncoder)
at Microsoft.AspNetCore.WebUtilities.HttpResponseStreamWriter.Dispose(Boolean disposing)
at System.IO.TextWriter.Dispose()
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable1 statusCode) at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable
1 statusCode)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
抱歉最近太忙回复迟了,我用您的代码测试了一下,无论是3.0还是3.1,都运行正常,没有任何问题,我注意了一下您的代码中这句:@using AspNetCorePage ,MvcCorePager中没有这个命名空间,感觉您用的应该不是现在这个MvcCorePager,请确认一下。谢谢!