I have a search page on an ASP.NET MVC5 application. There is a dropdown in the corner and if you select "User Search" the search filters for users appears. If you select "Task Search" the search filters for task shows.
These filters are being loaded in on partial views and are encapsultated in an Ajax.BeginForm
. So when an option is chosen, it loads an entirely new form.
@using (Ajax.BeginForm("SearchUsers", "Search", "Search_default",
new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "searchResults",
OnBegin = "StartSpinner",
OnComplete = "EndSpinner"
}))
{
//Form
}
The searchResults
div is on the page, so the forms are updating the content in a div on the main page with data in the form of another partial view.
Whichever search option I set as default, in this example users, works fine. When searching results come back and replace the div content as intended.
If I was then to switch to Task Search
which would replace the above form with one similar but pointing to a different action, the partial view returned for search results appears on a different page.
I am thinking it is because I am dynamically loading the form, it no longer recognises the searchResults
div but that could be way off. This can also be caused by unobstrusive.ajax.js if its not loaded however, the results work fine until I change the search form.