我的搜索功能似乎在无限循环中继续,每次我的调试点击 POST actionresult 下方的操作时都会被触发。
在我的 Masterpage.cshtml 中,我有以下操作:
<li>@Html.Action("Search", "Search")</li>
这是得到以下错误的部分:
堆栈不足,无法继续安全地执行程序。这可能是由于调用堆栈上有太多函数或堆栈上的函数使用了太多堆栈空间。
在我的 SearchController 中,我有一个 get 和 post actionresult 方法:
[HttpGet]
public ActionResult Search()
{
return PartialView("SearchFormPartial");
}
这个返回具有以下内容的局部视图:
@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>
}
它基本上是一个带有文本框和提交按钮的表单。
这是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");
}
它返回一个带有视图模型的视图,其中包含与查询匹配的项目。
当我调试它时,一切正常,但一切似乎都在无限重复。
Searchresult 的视图如下所示:
@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
}
}
这里到底出了什么问题导致这个无限循环?我该如何解决?
在堆栈跟踪中,我发现了这些异常
[HttpException (0x80004005): Error executing child request for handler
'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'。]
这个异常似乎在重复