Creating a search-form in umbraco using a surface controller
Hello!
I'm currently trying to implement a simple search page in umbraco using a surface controller. What I've got so far is as follows:
View (created from the umbraco backoffice with a doc type and
template)
The view calls Html.Action("GetSearchForm", "MyController") which in turn returns a partialview (_SearchForm) containing the form.
_SearchForm should render _SearchResults, that binds to _SearchForms Model.Results @Html.Partial("_SearchResults, Model.Results
I'm currently using Html.BeginUmbracoForm("FormSubmit"...) with
FormMethod set to post.
Posting to the action works fine, but when I've retrieved the results from the database (not the umbraco database) I want to return the partialview updated with the results, my controller looks something like this:
[HttpPost]
public ActionResult FormSubmit(SearchModel model)
{
if(!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
//Results is a List of type Result
model.Results = GetResults();
return PartialView("_SearchForm", model);
}
When I do this I end up losing the layout of the page, Sure, i get the partial-view rendered, and the results are there, but it's obviously wrong.
What am i doing wrong?
As of now, i've resorted to putting the results into
I've also set up a controller that inherits from RenderMvcController, and i've overridden the index
//Returning the view does not trigger this as far as i can see. It only fires on the first request of the page, which is why i'd say its safe to return a new MyModel()
public override ActionResult Index(RenderModel model)
{
//Please note that MyModel must inherit from RenderModel.
return base.Index(new MyModel());
}
! Please read the following
The controller inheriting from RenderMvcController should be named exactly as the view that was created in the backoffice
I've created a separate controller that inherits from SurfaceController, this now handles the httppost.
In my FormSubmit i can now do as follows:
[HttpPost]
public ActionResult FormSubmit(SearchModel model)
{
if(!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
//Results is a List of type Result
model.Results = GetResults();
return View("ViewCreatedInUmbracoBackOffice", model):
}
All of this allows me to still use the CurrentPage.GetGridHtml(), and the Umbraco.GetDictionaryValue(), which is super handy.
Creating a search-form in umbraco using a surface controller
Hello!
I'm currently trying to implement a simple search page in umbraco using a surface controller. What I've got so far is as follows:
View (created from the umbraco backoffice with a doc type and template)
_SearchForm should render _SearchResults, that binds to _SearchForms Model.Results
@Html.Partial("_SearchResults, Model.Results
I'm currently using Html.BeginUmbracoForm("FormSubmit"...) with FormMethod set to post.
Posting to the action works fine, but when I've retrieved the results from the database (not the umbraco database) I want to return the partialview updated with the results, my controller looks something like this:
When I do this I end up losing the layout of the page, Sure, i get the partial-view rendered, and the results are there, but it's obviously wrong.
What am i doing wrong? As of now, i've resorted to putting the results into
TempData["Results"] = GetResults(); return CurrentUmbracoPage();
but it's a solution that i find repulsive.
Use ajax call to controller via javascript or jquery like
In ajax's success function do DOM manipulation and add search content.
That is true, however i think i managed to fix it.
My main view now has the following:
ViewCreatedInUmbracoBackOffice.cshtml =
I've also set up a controller that inherits from RenderMvcController, and i've overridden the index
! Please read the following
The controller inheriting from RenderMvcController should be named exactly as the view that was created in the backoffice
I've created a separate controller that inherits from SurfaceController, this now handles the httppost.
In my FormSubmit i can now do as follows:
All of this allows me to still use the CurrentPage.GetGridHtml(), and the Umbraco.GetDictionaryValue(), which is super handy.
is working on a reply...