public class IsStudentValid : System.Web.Mvc.ActionFilterAttribute
{
public Int32 StudentId { get; set; }
public string ReviewStatus { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
StudentId = (Int32)filterContext.ActionParameters.SingleOrDefault(p => p.Key == "StudentId").Value;
if (StudentId != 0)
{
var validresult = db.Students.Where(c => c.StudentId == StudentId )
.Select(
c => new IsStudentValid {
CourseId=c.CourseId
ReviewStatus=c.ReviewStatus
} ).ToArray();
if (validresult.Count() == 0)
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary{{ "controller", "Admin" },
{ "action", "Login" }
});
}
}
base.OnActionExecuting(filterContext);
}
}
i have the above custom filter
but its not working properly
when i execute it first time i get all proper
but after changing the id in url when i try to run again it goes thr' the above code but i get error in razon view file as system.nullexception
the above attribute is not working properly