堆栈不足,继续执行程序安全 [英] Insufficient stack to continue executing the program safely

查看:1611
本文介绍了堆栈不足,继续执行程序安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图与ASP.NET的MVC 4的菜单。

I'm trying to make a menu with asp .net mvc 4.

呼叫菜单

@{Html.RenderAction("LeftMenu", "Navigation",
                      new { currentPoint = ViewData["CurrentCategory"] });}

导航控制器:

public ViewResult LeftMenu(string currentPoint) {

        List<NavLink> navLinks = new List<NavLink>();
        navLinks.Add(new CategoryLink(null)
        {
            IsSelected = (currentPoint == null)
        });

        List<string> categories = new List<string>{
            "Bicycles",
            "Details"
        };

        foreach (var category in categories)
            navLinks.Add(new CategoryLink(category){
                IsSelected = (category == currentPoint)
            });

        return View(navLinks);
    }

管窥

@model IEnumerable<MvcWebShopApp.Controllers.NavigationController.NavLink>
<ul class="nav navbar-nav">
    @foreach (var link in Model)
    {
        <li class = "@(link.IsSelected ? "active": "")">
            <a href="@Url.RouteUrl(link.RouteValues)")>@link.Text</a>
        </li>
    }
</ul>

但是,当我跑我的项目,我得到异常:

But when I run my project I got Exception:

不足堆继续安全地执行程序。这可以
  从具有调用堆栈或功能上过多的功能发生
  堆栈使用太多的堆栈空间。

Insufficient stack to continue executing the program safely. This can happen from having too many functions on the call stack or function on the stack using too much stack space.

请帮忙。

推荐答案

您实际上是在渲染一个全视图,而不是一个局部视图。结果
这包括布局,而这又使得这一观点,创造一个堆栈溢出。

You're actually rendering a full view, not a partial view.
That includes the layout, which renders that view again, creating a stack overflow.

您需要返回 PartialView()

这篇关于堆栈不足,继续执行程序安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆