Child actions are not allowed to perform redirect actions. (Using PartialViews)

前端 未结 4 1724
隐瞒了意图╮
隐瞒了意图╮ 2021-01-24 00:26

I\'m trying to load my partial view with some data from database, but I\'m getting following issue when I run the application:

Child actions are not allo

4条回答
  •  悲哀的现实
    2021-01-24 01:21

    Usually it happens when child Action has errors, because exception gets thrown and MVC trying redirect user to error page. In your case it is trying to find view named "Error, not found!", which probably you don't have. Try run Action as itself first, and check if logic works. Then put your view _UnreadEmails.cshtml in Manage Controller Views folder, and modify the code:

    public PartialViewResult UnReadEmails()
    {
       if (User.Id != null)
       {
          List resultList = EmailController.GetUnreadEmailsByUserId(User.Id);
           return PartialView("_UnReadEmails", resultList);
       }
       return PartialView("_UnReadEmails" new List());
    }
    

    Sometimes empty List means that nothing was found. OR:

    public ActionResult UnReadEmails()
    {
       if (User.Id != null)
       {
          List resultList = EmailController.GetUnreadEmailsByUserId(User.Id);
           return PartialView("_UnReadEmails", resultList);
       }
       return Content("Error, not found!");
    }
    

提交回复
热议问题