5
工作,而在_Layout.cshtml文件我有以下條目:兒童的行爲是不允許進行重定向操作 - 錯誤與ASP.NET MVC 2和剃刀
@Html.Action("LoadPagesStructure", "Page")
內的PageController類,LoadPagesStructure methos看起來如下:
[ChildActionOnly] /* this attribute indicates that an action should not
be invoked as a result of a user request (by url) */
public ActionResult LoadPagesStructure()
{
ViewModel.Pages = new List<string>() {"page1", "page2", "page3"};
return View();
}
最後,我LoadPagesStructure.cshtml觀點看起來象下面這樣:
@inherits System.Web.Mvc.WebViewPage<dynamic>
<ul>
@foreach (var page in View.Pages) {
<li>
@Html.ActionLink(page, "Index", "Home")
</li>
}
</ul>
不幸的是,一個異常被執行後拋出:
System.InvalidOperationException: Child actions are not allowed to perform redirect actions.
什麼是創建鏈接到動態我的網頁的方式嗎?
PS:我知道我可以這樣做:<a href="@page">@page</a>
。不過,我認爲這不是正確的方法,因爲在這裏不可能控制路由。
問候