我使用ASP.NET MVC 3.0和得到以下錯誤在* _shared \ Layout.cshtml *ASP.NET MVC 3.0 - 錯誤執行的處理子請求 'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'
執行處理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'的子請求時出錯。
我在@{ 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>
在控制器出現錯誤\ 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);
}
}
}
在瀏覽\導航\ 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
}
)
}
這解決了我的問題! – 2013-06-02 21:41:37