我正在爲asp.net MVC佈局頁面設置共享內容(導航)。ASP.NET MVC 3局部視圖佈局頁面
這是我的部分視圖「_LayoutPartial.cshtml」,帶有從模型中提取導航數據的代碼。
@model MyApp.Models.ViewModel.LayoutViewModel
<p>
@foreach (var item in Model.navHeader)
{
//Test dump of navigation data
@Html.Encode(item.Name);
@Html.Encode(item.URL);
}
</p>
下面是我的控制器「LayoutController.cs」的代碼的外觀。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyApp.Models.ViewModel;
namespace MyApp.Controllers
{
public class LayoutController : Controller
{
//
// GET: /Layout/
LayoutViewModel layout = new LayoutViewModel();
public ActionResult Index()
{
return View(layout);
}
}
}
這裏是「_Layout.cshtml」頁面的代碼。我試圖使用Html.RenderAction(Action,Controller)方法在這裏調用部分視圖。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<p>
@{Html.RenderAction("Index","Layout");}
</p>
@RenderBody()
</body>
</html>
當佈局頁面執行@ {Html.RenderAction(「索引」,「佈局」);}線,就拋出執行子請求處理程序「System.Web.Mvc錯誤消息「錯誤.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper」。」
我在想什麼朋友?如何在佈局頁面中調用部分視圖?
謝謝大家提前!
哪裏是您的局部視圖位於 – 2012-07-12 19:53:57
〜/查看/共享/ _LayoutPartial.cshtml – Felasfaw 2012-07-12 20:02:53