Solved : Search Results Not Rendering after upgrade to CMS 12

Vote:
 

We have recently upgraded to CMS 12 and we are having issue rendering the search results.

When we debug we are seeing the final filtered search results returned by our SearchController which is derived from a API Controller but this changed in CMS 12 now they are using ControllerBase instead of API Controller. 

Our SearchController was suppose to return the results to SearchPageController when the search results are to be rendered but it looks like the SearchControler is trying to render the results which doesn't have a view assocated with it.

Any idea on how we can fix this.

#286103
Edited, Aug 25, 2022 4:29
Vote:
 

Can you provide the upper part of your SearchController : ControllerBase class?

#286105
Aug 25, 2022 7:04
Vote:
 

Here are the classes

This is the search controller
[Route("api/[controller]")]
    [ApiController]
    public class TestController : ApiControllerBase
   

This is the ApiControllerBase
  public abstract class ApiControllerBase : ControllerBase   
    {

#286125
Aug 25, 2022 20:00
Vote:
 

Hi Durga, nothing wrong the snippet you've posted.

How about more information about the "trying to render the results which doesn't have a view assocated with it". What does this look like exactly?

#286127
Aug 25, 2022 22:18
Vote:
 

Hi Surjit,

My TestContoller is the one which does the actual search, filtering and creates the search results. The one thing we noticed is we have a PageContextActionFilter see the code below.

In CMS 11 the API Controller never executed this code but now in CMS 12 because we are using the ControllerBase class this gets called and the view model is null, not sure how to avoid this call for the Test Controller.

public void OnResultExecuting(ResultExecutingContext context)
        {
            var controller = context.Controller as Controller;
            var viewModel = controller?.ViewData.Model;

            if (viewModel is IPageViewModel<SitePageData> model)
            {
                var currentContentLink = context.HttpContext.GetContentLink();

                var layoutModel = model.Layout ?? _contextFactory.CreateLayoutModel(currentContentLink, context.HttpContext);

                if (context.Controller is IModifyLayout layoutController)
                {
                    layoutController.ModifyLayout(layoutModel);
                }

                model.Layout = layoutModel;

                            }
        }

#286129
Aug 25, 2022 22:52
Vote:
 

Ah I see. I'm going to assume this is inside of a global result filter.

You could move to to an attribute and apply the page controllers.

Alternatively if thats too much hassle then instead extend the first if statement to check to see if its an api call? a few suggestions:

a) See if the request url starts with api. e.g. context.HttpContext.Request.Path.Value.StartsWith("/api/")

b) or look at the RouteData to check the controller name.

#286165
Aug 26, 2022 0:11
Vote:
 

we want to make sure the Api controller doesn't even come to this function and returns the control back to the page controller with the view to render the results.

#286224
Aug 26, 2022 23:08
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.