【问题标题】:PageListPaper Html helper throws an error "security critical type 'System.Web.Mvc.MvcHtmlString' failed"PageListPaper Html 助手抛出错误“安全关键类型'System.Web.Mvc.MvcHtmlString'失败”
【发布时间】:2015-06-06 23:25:31
【问题描述】:

查看下面列出的文件

     @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”失败。

Assembly 'PagedList.Mvc,版本=3.18.0.0,文化=中性, PublicKeyToken=abbb863e9397c5e1' 标有 AllowPartiallyTrustedCallersAttribute,并使用 2 级安全性 透明度模型。 2 级透明度导致所有方法在 AllowPartiallyTrustedCallers 程序集变得安全透明 默认情况下,这可能是导致此异常的原因。

期待解决方案。提前致谢。

【问题讨论】:

    标签: c# asp.net-mvc-4


    【解决方案1】:

    您必须安装最新的 PagedList.Mvc 版本 4.5.0,如果您安装了 PagedList.MVC,它会自动将您的 PagedList 版本 1.15 更新到 1.17.0 试试下面的命令

    PM> Install-Package PagedList.Mvc
    

    【讨论】:

      猜你喜欢
      • 2017-03-15
      • 2020-10-10
      • 2020-11-10
      • 2020-03-17
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      • 2015-08-19
      • 2018-11-06
      相关资源
      最近更新 更多