I have something a little complicated, but I don’t understand why this will not work: I have JSTree in my Index.cshtml. When node is selected, I make an Ajax call
public async Task<ActionResult> GetEBooksItems(string id)
which return a partial view. This works EXCELLENT GOOD.
Now, in addition to searching for a tree, I have a form to add some criteria to narrow my search. I am using Ajax.BeginForm to send data back to the controller.
public async Task<ActionResult> GetEBooksCustom(GenericSearchViewModel filter) { vm = filter; //Session["GenreNodeId"] = id; Session["SearchCondition"] = (string.IsNullOrEmpty(vm.Condition) != true) ? vm.Condition : "All"; Session["MaximumPrice"] = (string.IsNullOrEmpty(vm.MaxPrice) != true) ? vm.MaxPrice : "999999"; Session["MinimumPrice"] = (string.IsNullOrEmpty(vm.MinPrice) != true) ? vm.MinPrice : "0"; Session["SearchIndex"] = (string.IsNullOrEmpty(vm.SearchIndex) != true) ? vm.SearchIndex : "KindleStore"; Session["SortOrder"] = (string.IsNullOrEmpty(vm.SortOrder) != true) ? vm.SortOrder : "price"; Session["KeyWords"] = (string.IsNullOrEmpty(vm.Keywords) != true) ? vm.Keywords : ""; Session["Title"] = (string.IsNullOrEmpty(vm.Title) != true) ? vm.Title : ""; Session["Author"] = (string.IsNullOrEmpty(vm.Author) != true) ? vm.Author : ""; return RedirectToAction("GetEBooksItems", new { id = vm.CategoryNodeId }); }
to this method, which in turn calls the first using RedirectToAction.
I try everything that I could think of, always get the results as a whole page, and not a partial representation, as in the first method.
It seems that calling GetEBooksCustom is not considered as an Ajax call. What am I missing? Thanks for your help, Bernard.
**** Edit after 6 hours **********
In between, I did what was suggested, that is, extract the functions from "GetEBooksItems" so that I could directly return a PartialView instead of using RedirectToAction. In the debugger it seems that everything is perfect, I see a 200 response from the server, BUT I still get a full pageview, and the url displays the controller method, while this should not be for ajax call.
The fact is that I basically have the same form somewhere else, where it works as expected. I can’t understand what could be different.
As always, thanks for your help and suggestions. Bernard