不足堆继续安全地执行程序。 ASP.NET MVC 4 [英] Insufficient stack to continue executing the program safely. ASP.NET MVC 4

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

问题描述

我的搜索功能,似乎继续在无限循环,每次我调试射门集中立柱下方的ActionResult动作被炒鱿鱼。

在我Masterpage.cshtml我有以下动作:

 <立GT; @ Html.Action(搜索,搜索)< /李>

这是获取以下错误的部分:


  

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


在我SearchController我有一个GET和POST方法的ActionResult:

  [HTTPGET]
        公众的ActionResult搜索()
        {
            返回PartialView(SearchFormPartial);
        }

这其中一个返回具有下列内容的局部视图:

  @using(Ajax.BeginForm(搜索,搜索,FormMethod.Post,
        新AjaxOptions
        {
            InsertionMode = InsertionMode.Replace,
            列举HTTPMethod =POST         }))
{
< D​​IV>
    @ Html.TextBox(查询,,新{@class =搜索查询,@占位=搜索新闻...,@拼写检查=假})
    <输入类型=提交值=搜索/>
< / DIV>
}

其basicly与文本的格式,并提交按钮。

这是HTTP POST的ActionResult:

  [HttpPost]    公众的ActionResult搜索(查询字符串)
    {
        如果(查询!= NULL)
        {
            尝试
            {                VAR searchlist = rep.Search(查询);                VAR模型=新ItemViewModel()
                {
                    新闻列表=新的List< NewsViewModel>()
                };                的foreach(在searchlist VAR NewsItems)
                {
                    FillProductToModel(型号,NewsItems);
                }
                返回视图(SearchResult所,模型);
            }
            赶上(例外五)
            {
                //处理异常
            }
        }
        返回视图(错误);
    }

它返回一个包含匹配查询项的视图模型视图。

当我调试它一切完美,但一切似乎infinitly重复。

对于信息搜索结果的看法是这样的:

  @model Namespace.ViewModels.ItemViewModel
@if(Model.NewsList.Count == 0)
{
    < H3类=TEXT-错误>没有项目符合您的搜索查询和LT;!/ H3 GT&;
}
其他
{
    的foreach(在Model.NewsList VAR结果)
    {
        //显示搜索结果
    }
}

什么是exacly会错在这里,造成这种无限循环?我怎样才能解决这个问题?

在堆栈跟踪,我发现这些异常


  [HttpException(0x80004005的):错误执行的孩子处理请求


  
  

System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'。]


此异常似乎得到重复


解决方案

Html.Action 在母版页调用一个POST请求的搜索方法,所以该框架赢得 ŧ调用返回,返回与母版页的ViewResult局部视图,但其他的动作。同样的事情会再次发生,你将作出递归调用。

最简单的解决办法是重命名响应POST请求的搜索行动。另外,还要确保你的帖子的形式向这个动作,但保持相同的 Html.Action 电话。

好像框架将仍然试图找到能够为POST请求做出响应的动作。删除 HTTPGET 从搜索行为属性将解决这个问题。

My search functionality seems to continue in a infinite loop, everytime my debug hits the action below the POST actionresult gets fired.

In my Masterpage.cshtml I have following action:

 <li>@Html.Action("Search", "Search")</li>

This is the part that gets the error of following:

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.

In my SearchController I have one get and post actionresult methods:

[HttpGet]
        public ActionResult Search()
        {
            return PartialView("SearchFormPartial");
        }

This one returns a partial view that have following content:

@using (Ajax.BeginForm("Search", "Search", FormMethod.Post,
        new AjaxOptions
        {
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "POST"

         }))
{
<div>
    @Html.TextBox("query", "", new { @class = "search-query", @placeholder="Search news...", @spellcheck="false"})
    <input type="submit" value="Search" />
</div>      
}

Its basicly a form with the textbox and submit button.

This is the http post actionresult:

[HttpPost]

    public ActionResult Search(string query)
    {
        if (query != null)
        {
            try
            {

                var searchlist = rep.Search(query);

                var model = new ItemViewModel()
                {
                    NewsList = new List<NewsViewModel>()
                };

                foreach (var NewsItems in searchlist)
                {
                    FillProductToModel(model, NewsItems);
                }


                return View("Searchresults", model);
            }
            catch (Exception e)
            {
                // handle exception
            }
        }
        return View("Error");


    }

It returns a view with a viewmodel that contains the items that matched the query.

When I debug it everything works perfectly but everything seems to be repeated infinitly.

The view for the Searchresult looks like this:

@model Namespace.ViewModels.ItemViewModel
@if (Model.NewsList.Count == 0)
{
    <h3 class="text-error">No items matched your search query!</h3>
}
else
{
    foreach (var result in Model.NewsList)
    {
        // display search results
    }
}

What is exacly going wrong here that cause this infinite loop? and how can I fix it?

In the stack trace I found these exceptions

[HttpException (0x80004005): Error executing child request for handler

'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]

this exception seems getting repeated

解决方案

Html.Action in master page calls the Search method with a POST request, so the framework won't call the action that returns the partial view but the other that returns a ViewResult with the master page. Same thing will happen again and you will be making recursive calls.

Simplest solution would be to rename the Search action that responds to POST request. Also make sure your form posts to this action but keep the same Html.Action call.

It seems like framework will still try to find the action that can respond to a POST request. Removing HttpGet attribute from Search action will solve this problem.

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

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