ASP.NET MVC 3.0 - Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'

I am using ASP.NET MVC 3.0 and am getting the following error in * _Shared \ Layout.cshtml *

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'.

I am getting error when @{ Html.RenderAction("Menu", "Nav"); }

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
</head>

<body>
    <div id = "header">
        <div class = "title">SPORTS STORE</div>
    </div>

    <div id = "categories">


      @{ Html.RenderAction("Menu", "Nav"); }
    </div>

    <div id = "content">
        @RenderBody()
    </div>

</body>
</html>

      


In controllers \ NavController:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SportsStore.Domain.Abstract;
using SportsStore.WebUI.Models;

namespace SportsStore.WebUI.Controllers
{
    public class NavController : Controller
    {
        private IProductRepository repository;

        public NavController(IProductRepository repo)
        {
            repository = repo;
        }


        public PartialViewResult Menu()
        {

            IEnumerable<string> categories = repository.Products
                                    .Select(x => x.Category)
                                    .Distinct()
                                    .OrderBy(x => x);

            return PartialView(categories);
        }

    }
}

      


In the views \ Nav \ Menu.cshtml:

@model IEnumerable<string>

@
{
    Layout = null;
}

@Html.ActionLink("Home", "List", "Product")

@foreach (var link in Model)
{
    @Html.RouteLink(link, new
        {
            controller = "Product",
            action = "List",
            category = link,
            page = 1
        }
    )
}   

      

+3


source to share


2 answers


I could get this example to work.

However, there is a problem with the code when it is posted. Notice the line break in your example:

@ 
{ 
    Layout = null; 
} 

      

As long as it really should be



@{ 
    Layout = null; 
} 

      

It generates the error you specified "Error executing child request for handler" System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper "which is useless, but when I hit F5 I was taken to a better description page:

Parser Error: An error occurred while parsing a resource required to service this request. Review the following parsing error details and modify the source file accordingly.

Parser error message: A space or line break occurred after the "@" character. Only valid identifiers, keywords, comments "(" and "{" are valid at the beginning of a block of code, and must occur immediately after the "@" with no space in between.

+3


source


Use [ChildActionOnly]

an attribute Menu

like:



[ChildActionOnly] 
public PartialViewResult Menu()
{
    IEnumerable<string> categories = repository.Products
                                .Select(x => x.Category)
                                .Distinct()
                                .OrderBy(x => x);

    return PartialView(categories);
}

      

+2


source







All Articles