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