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

Asked

Viewed 2,820 times

4

I’m basically developing a kind of social network, but I’m having some problems rendering pages inside 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’re making this mistake

A public action method 'Requesttoaccept' was not found on controller 'Manylife.ASP.Areas.Professional.Controllers.Professionaluserhasclientcontroller'.

If I modify for 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 am doing the best way, but the print below shows the situation, I need to access the "Requesttoaccept.cshtml" in that open tab on the right side, and every view exchange reloads it, because it is waiting for requests for "friendship requests":

inserir a descrição da imagem aqui

Man Controller

[Authorize]
public class ProfessionalUserHasClientController : Controller
{
    public ActionResult Dashboard(ProfessionalUser pUser)
    {
        List<SimpleUser> listProfessionalUserHasClient = new List<SimpleUser>();

        using (ProfessionalUserDAO dao = new ProfessionalUserDAO())
        {
            listProfessionalUserHasClient = dao.ListProfessionalHasClient(pUser.IdProfessionalUser);
        }

        return View(listProfessionalUserHasClient);
    }

    [HttpPost]        
    public ActionResult RequestToAccept()
    {
        ProfessionalUser pUser = 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 menu on the left to call other views from other controls, it says that I’m trying to load a Simpleuser type object into a View that expects a List from a type object "x", in the action that he should pass, he returns this list normally to the View.

  • I believe your problem is that your controller methods are POST. Remove Annotation [Httppost] from Requesttoaccept and try again.

  • @Vinícius {Cannot evaluate Expression because the Current thread is in a stack overflow state.}

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()
{
    ...
}
  • I updated with a note below, I don’t know if you saw it, but this code you sent me tested and generated the following Exception: {Cannot evaluate Expression because the Current thread is in a stack overflow state. } ... the line it generated is the @Scripts.Render("~/Bundles/jquery") of _Layout.cshtml

  • It means that the Bundling is being called countless times, giving stack burst. Has Bundling in your Views? The right is that the @Scripts.Render() stay only in View _Layout.

  • only has in _Layout same.

  • I think he’s called _Layout every time. I modified the answer with one more attribute. Take a test.

  • Remained the error.

  • I don’t know if you read the note I added, why with Renderpage it opens, if I click on the Dashboard tab it even recharges perfectly, but when I click on the tabs below to load the actions of other controllers from that error saying I’m passing an object (?) other than what the View expects (being that in the action of such a view, it returns the perfect list). Only it doesn’t even go into view.

  • How are the ActionLinks for other Views methods?

  • @Html.Actionlink("Patients", "List", "Professionalhasclient") all in this standard.

  • That would be the scope of another question. I don’t know what’s causing it with what I have in this question.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.