November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Can you provide the upper part of your SearchController : ControllerBase class?
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
{
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?
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;
}
}
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.
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.
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.