当你在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;}

这两种方法都有效。

 

相关文章:

  • 2021-11-12
  • 2021-09-20
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-01-11
  • 2022-01-26
猜你喜欢
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案