Gravatar for wvuong@captechconsulting.com

Question by wvuong, Dec 11, 2015 10:51 AM

Converting Search View MVC into Controller Rendering

I am trying to convert the view rendering for Search View MVC into a controller rendering but am having trouble passing the model to the view.

If I don't specify a model in my controller to pass when returning the view, the model will be null, otherwise I'm not sure how to retrieve a model for the search view

1 Reply
Gravatar for slangevin@coveo.com

Answer by Simon, Dec 22, 2015 3:20 PM

Hi,

Here are the steps to set the view with the model.

  1. We create the view and Sitecore returns a Sitecore.Mvc.Presentation.Rendering object.
  2. We create the model using the Coveo.UI.Mvc.Models.SearchModel()
  3. We instantiate the model using the Sitecore Initialize method: myModel.Initialize(myViewRendering)
  4. This allow the Model to grab the parameters from the view.
  5. The view is rendered.

This said, you could instantiate the Sitecore.Mvc.Presentation.Rendering object by yourself (all the properties of the class are public) and then call the initialize method on our model. Just make sure that the Rendering object you created contains all the parameters that the model need.

Gravatar for wvuong@captechconsulting.com

Comment by wvuong, Jan 18, 2016 3:02 PM

Thanks, this worked out. In case anyone is wondering how to get the existing rendering "Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering" will get you it. Then you can follow the instructions above calling myModel.initialize with that rendering

Ask a question