1
votes

I have a controller rendering on my homepage which is a search box.

My controller action looks like this

public ActionResult Search(SearchResultModel model)
    {
        //TODO bind to model to form
        SearchModel resultModel = new SearchModel
        {
            Keyword = Request.Form["keyword"]
        };
        var results = new List<SearchResultModel>();
        results = FoundResults(resultModel.Keyword);
        resultModel.SearchResults = results;

        return View(resultModel);
   }

What is it I want? I want to fill in a keyword in the input box have it processed ( and posted ) and return a page ( item ) in sitecore with my model. Something like return item and give it my model.

Question. Is this possible ?

If not? What would be the best way to tackle this issue?

I need some help here folks :).

I have already read :

http://mhwelander.net/2014/05/22/passing-data-between-actions-in-sitecore-mvc/

and other articles from Martina but I seem to not be getting anywhere closer.

1
A controller action does not return a "page" - it returns the data required for the specific rendering. If you want to change the page in the controller action you need to redirect the user to that other page and let the renderings on that page present the data.Richard Seal
I suggest you to made a ajax call when you press search button and return a json with results. After you render json results on the page.Vlad Iobagiu
I need to avoid ajax calls we need to be able to present the data even if js is disabled. I did use ajax way in another project.k.zaraki
Can you clarify your need please ? you action SearchResultModel takes an argument which is not used ! you want one item or a list of items ? what should this item contain ? should it be of a certain template or contain a keyword ??lyz
The problem is not in the model or items. That works. The "problem" lies in the fact that I want to return a page in sitecore with my populated model( that I have already set in this controller).k.zaraki

1 Answers

0
votes

Thank you all for your ansers. I have figured out how I could get what I wanted. I had to remain within the Sitecore pipeline so I decided to use querystrings to achieve this goal. This worked out perfectly.

I used my Searchbox post action to Redirect to the Searchpage that had controller renderings.