【发布时间】: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