November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Not sure what happened with my question, but here it is again:
Hello, I'm trying to build a custom SearchForm that is called in my _Layout.cshtml file, but the problem is when I redirect the searchResult to a SearchPage it doesn't get a currentPage, and Joel Abrahamssons NavigationHelper.cs method RenderMainNavigation() crashes because currentPage is null (even though the page isn't displayed in navigation).
Here's my code in the controller:
public ActionResult Search(SearchPage currentPage) { var model = new SearchPageViewModel(currentPage); return View(); } [HttpPost] public ActionResult Search(string searchField) { var model = new SearchPageViewModel(); model = ConnectionHelper.Search(searchField); return View("Search", model); }
Simple form in _Layout.cshtml:
@using (Html.BeginForm("Search", "SearchPage", FormMethod.Post)) { @Html.TextBox("searchField") <button type="submit" class="btn searchButton">Sök</button> }
Any idea of how I can get a SearchPage as currentPage in the controller?
I've tried changing the return type to RedirectToAction and putting the node as a pageReference I chose in the StartPage, but that doesn't work as the model and the node mix, making the model in the view mismatch and crash.
Not sure if this is done correctly, but I solved it by changing it to this:
public ActionResult Index(SearchPage currentPage) { SearchPageViewModel lists = (SearchPageViewModel)Session["Model"]; Session.Clear(); var model = new SearchPageViewModel(currentPage); model.eventResults = lists.eventResults; model.userResults = lists.userResults; model.SearchQuery = lists.SearchQuery; return View(model); } [HttpPost] public ActionResult Search(string searchField) { var model = new SearchPageViewModel(); var page = new SearchPage(); var pageReference = page.StartPage.SearchPageUrl; model = ConnectionHelper.Search(searchField); model.SearchQuery = searchField; Session["Model"] = model; return RedirectToAction("Index", pageReference); }
And the variable pageReference is a PageReference I set in my StartPage that points toward the searchPage.
Hello, I'm trying to build a custom SearchForm that is called in my _Layout.cshtml file, but the problem is when I redirect the searchResult to a SearchPage it doesn't get a currentPage, and Joel Abrahamssons NavigationHelper.cs method RenderMainNavigation() crashes because currentPage is null (even though the page isn't displayed in navigation).
Here's my code in the controller:
Simple form in _Layout.cshtml:
Any idea of how I can get a SearchPage as currentPage in the controller?
I've tried changing the return type to RedirectToAction and putting the node as a pageReference I chose in the StartPage, but that doesn't work as the model and the node mix, making the model in the view mismatch and crash.