我在我的asp.net mvc 5应用程序中使用PagedList Nuget包。 以下是我想要的来源:
@Html.PagedListPager(Model, page => Url.Action("StudentList",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
当我在我的观点中使用它时,它会抛出异常:
System.TypeAccessException was unhandled by user code
HResult=-2146233021
Message=Attempt by security transparent method 'PagedList.Mvc.HtmlHelper.PagedListPager(System.Web.Mvc.HtmlHelper, PagedList.IPagedList, System.Func`2<Int32,System.String>)' to access security critical type 'System.Web.Mvc.MvcHtmlString' failed.
Assembly 'PagedList.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=abbb863e9397c5e1' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
Source=PagedList.Mvc
TypeName=""
StackTrace:
at PagedList.Mvc.HtmlHelper.PagedListPager(HtmlHelper html, IPagedList list, Func`2 generatePageUrl)
at ASP._Page_Views_Registration_StudentList_cshtml.Execute() in c:\Users\maifs\SkyDrive\SchoolManagementSystem\SMSApp\Views\Registration\StudentList.cshtml:line 57
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.StartPage.RunPage()
at System.Web.WebPages.StartPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
InnerException:
我试图在assemblyinfo.cs中使用这些属性
[assembly: SecurityRules(SecurityRuleSet.Level2)]
和
[assembly: AllowPartiallyTrustedCallersAttribute]
但它没有用。请指导我。感谢
答案 0 :(得分:2)
Nuget Package Manager, Update-Package PagedList.Mvc
我的问题已修复。