我的non static method requires a target
出现ActionExecutingContext Filter
错误,此过滤器会搜索数据库上的某些数据并通过ViewBag of the filterContext
将其提供给被叫控制器,这是代码:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
using (var db = new Entities())
{
var redirect = MvcApplication.reqContext;
var seos = db.SEO.Where(x => x.ID == redirect.seoId).ToList();
var desconto = db.QueroDesconto.First();
//Recupera cookie banner home
filterContext.Controller.ViewBag.BannerHome = filterContext.HttpContext.Request.Cookies["BannerHome"] != null ? int.Parse(filterContext.HttpContext.Request.Cookies["BannerHome"].Value) : 0;
filterContext.Controller.ViewBag.objEstados = objEstados;
filterContext.Controller.ViewBag.Desconto = desconto;
base.OnActionExecuting(filterContext);
}
}
问题是,只有在我访问MVC区域时才会发生这种情况,并且在我调试时从未发生过
答案 0 :(得分:-1)
问题出在我的数据库搜索中,我在redirect var
中收到空值。
此var仅在我的路径处理程序控制器中的根项目中填充,每次我询问时都会执行此操作。对于一个页面,由于我的区域没有执行这个控制器,我总是得到空值。
现在,调试工作的唯一工作正在发生,因为每次我调试它,默认情况下,我会从根项目开始,因此具有空值