簡體   English   中英

PageListPaper Html幫助程序拋出錯誤“安全關鍵類型'System.Web.Mvc.MvcHtmlString'失敗”

[英]PageListPaper Html helper throws an error “security critical type 'System.Web.Mvc.MvcHtmlString' failed”

查看下面列出的文件

     @using PagedList;
        @using PagedList.Mvc;


        @model IPagedList<MVCDemo.Models.Employee>
       <table> 
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.First().Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.First().Gender)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.First().Email)
        </th>
        <th>Action</th>
    </tr>
   </table> 

       @Html.PagedListPager(Model, page => Url.Action("Index", new { page, searchBy = Request.QueryString["searchBy"], search = Request.QueryString["search"] }))

控制器動作方法在這里顯示

public ActionResult Index(string searchBy, string search, int? page)
{
    if (searchBy == "Gender")
    {
        return View(db.Employees.Where(x => x.Gender == search || search == null).ToList().ToPagedList(page ?? 1, 3));
    }
    else
    {
        return View(db.Employees.Where(x => x.Name.StartsWith(search) || search == null).ToList().ToPagedList(page ?? 1, 3));
    }
}

當我使用上面的代碼時,以下錯誤引發

附加信息:嘗試通過安全透明方法'PagedList.Mvc.HtmlHelper.PagedListPager(System.Web.Mvc.HtmlHelper,PagedList.IPagedList,System.Func`2)'訪問安全關鍵類型'System.Web.Mvc.MvcHtmlString'失敗。

程序集'PagedList.Mvc,版本= 3.18.0.0,區域性=中性,PublicKeyToken = abbb863e9397c5e1'標記有AllowPartiallyTrustedCallersAttribute,並使用2級安全透明性模型。 級別2透明導致默認情況下AllowPartiallyTrustedCallers程序集中的所有方法變為安全透明,這可能是導致此異常的原因。

期待解決方案。 提前致謝。

您必須安裝最新的PagedList.Mvc版本4.5.0,如果安裝了PagedList.MVC,它將自動將您的PagedList版本1.15更新為1.17.0。

PM> Install-Package PagedList.Mvc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM