我的搜索功能似乎在無限循環中繼續,每當我的調試命中POST actionresult下面的動作時就會被觸發。堆棧不足以繼續安全地執行程序。 ASP.NET MVC 4
在我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>
}
其basicly形式與文本框並提交按鈕。
這是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");
}
它返回一個包含與查詢匹配的項的視圖模型視圖。
當我調試它時,一切正常,但似乎無限重複了一切。
的信息搜索結果的看法是這樣的:
@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
}
}
什麼exacly去錯在這裏,造成這種無限循環?我該如何解決它?
在堆棧跟蹤,我發現這些異常
[HttpException (0x80004005): Error executing child request for handler
'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'。]
這個例外似乎得到重複
nope但是當迭代完成時,它跳轉到masterpage.cshtml並且Html.Action(「Search」,「Search」「)在那裏。 – Obsivus
當您發佈到搜索操作時,您是否收到錯誤消息? –
當我停止運行webb應用程序時,出現錯誤..其它只是無限循環,這意味着當我鍵入文本並單擊提交它的剛纔加載時 – Obsivus