Render pages within _Layout.cshtml of other types. Asp.Net MVC 4

4

I'm basically developing a kind of social network, however I'm having some problems rendering pages within my _Layout.cshtml page.

Html

<ul class="dropdown-menu">
    <li class="header">Você tem @pUser.RequestsToAccept.Count requisições enviadas.</li>
    @{Html.RenderAction("RequestToAccept", "ProfessionalUserHasClient");}
    <li class="footer"><a href="#">Últimas requisições enviadas</a></li>
</ul>

You are giving this error

  

A public action method 'RequestToAccept' was not found on controller 'ManyLife.ASP.Areas.Professional.Controllers.ProfessionalUserHasClientController'.

If I modify to RenderPage

<li class="header">
    Você tem @pUser.RequestsToAccept.Count requisições enviadas.
</li>
@RenderPage("~/Areas/Professional/Views/ProfessionalUserHasClient/RequestToAccept.cshtml")
<li class="footer"><a href="#">Últimas requisições enviadas</a></li>

{"Erro ao executar a solicitação filho do manipulador 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'."}

I do not know if I'm doing the best, but the print below shows the situation, I need to access the "RequestToAccept.cshtml" in that open tab on the right side, and with each view change it reloads it, since it keeps waiting for requests of requests for "friendship":

MyController

[Authorize]publicclassProfessionalUserHasClientController:Controller{publicActionResultDashboard(ProfessionalUserpUser){List<SimpleUser>listProfessionalUserHasClient=newList<SimpleUser>();using(ProfessionalUserDAOdao=newProfessionalUserDAO()){listProfessionalUserHasClient=dao.ListProfessionalHasClient(pUser.IdProfessionalUser);}returnView(listProfessionalUserHasClient);}[HttpPost]publicActionResultRequestToAccept(){ProfessionalUserpUser=Session["ProfessionalUserLogged"] as ProfessionalUser;

        return View(pUser.RequestsToAccept);
    }

    [HttpPost]
    public ActionResult RequestSended()
    {
        ProfessionalUser pUser = Session["ProfessionalUserLogged"] as ProfessionalUser;

        return View(pUser.RequestSended);
    }
}

NOTE: I forgot to tell you that using @RenderPage it loads normally, but when I use the left menu to call other views from other controls, it says I'm trying to load an object of type SimpleUser into a View that expects a List of an object type "x" , and in the action that it should pass, it returns this list normally to the View.

    
asked by anonymous 21.05.2014 / 22:11

1 answer

5

Modify:

[HttpPost]        
public ActionResult RequestToAccept()
{
    ProfessionalUser pUser = Session["ProfessionalUserLogged"] as ProfessionalUser;

    return View(pUser.RequestsToAccept);
}

To:

[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
[ChildActionOnly]
public ActionResult RequestToAccept()
{
    ...
}
    
21.05.2014 / 22:23