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

前端 未结 4 1715
隐瞒了意图╮
隐瞒了意图╮ 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:02

    At the end I decided to skip my PartialViewResult method from a controller and do it on another way, because I've allready lost 2 days trying to find an answer and it wasn't there, but something else seems to be working, and it was this:

    {@Html.RenderPartial("~/Views/Emails/_UnReadEmails.cshtml",EmailController.GetUnreadEmailsByUserId(User.Id))}
    

    What I did there was next, I called directly GetUnreadEmaisByUserId method from my BussinesLogic part, and everything worked like charm.

    And what we might do here to make this solution better is next:

    In case we dont have a "main model" we could store that in a ViewBag, calling this from a MessageController/Email controller method

    ViewBag.lstUnreadEmail‌s = E‌​mailController.Get‌‌​​Un‌​readEmailsByUserId(U‌​ser.Id);
    And in the View use this
    
    {@Html.RenderPartial("~/Views/Emails/_UnReadEmails.cshtml",ViewBag.lstUnreadEmail‌​s}
    

提交回复
热议问题