當你在layout里使用Html.RenderAction加載局布頁面的時候,直接進入死循環。
@{ Html.RenderAction("Index", "Status"); }
主要問題,在Index的View, 我在Index Action 返回的是VIEW,RenderAction是在_Layout.cshtml中運行,每一個View都會調用_layout.cshtml,調用時候Action又調用View, View又調用_layout.cshtml,所以就進入了死循環。
兩種解決方案:
1、Index Action不返回View,而是PartialView
public PartialViewResult Index() { //dosomething return PartialView(); }
2、在Index 的View中加上 @{ layout=null;}
這兩種方法都有效。