PascalEugster
09/05/2023, 9:38 AMPascalEugster
09/05/2023, 9:38 AMRavi
09/05/2023, 10:28 AMPascalEugster
09/05/2023, 11:22 AMD_Inventor
09/05/2023, 12:00 PM@inherits SearchPageViewModel
Should be one of these:
@model SearchPageViewModel
or
@inherits UmbracoViewPage<SearchPageViewModel>
PascalEugster
09/05/2023, 12:05 PMPascalEugster
09/05/2023, 12:18 PMD_Inventor
09/05/2023, 12:26 PMD_Inventor
09/05/2023, 12:27 PMRenderController
as your base class for rendering content pages. That's specifically what that base class is forD_Inventor
09/05/2023, 12:29 PM@inherits UmbracoViewPage
and use either the Umbraco helper or the Umbraco Context to get the current page.PascalEugster
09/05/2023, 12:32 PMD_Inventor
09/05/2023, 12:33 PMPascalEugster
09/05/2023, 12:49 PMPascalEugster
09/05/2023, 12:57 PMPascalEugster
09/05/2023, 12:57 PMPascalEugster
09/05/2023, 12:58 PMD_Inventor
09/05/2023, 1:57 PMUmbracoViewPage
class though, otherwise you can't get the assigned content item.D_Inventor
09/05/2023, 1:58 PMIUmbracoContextAccessor
instead and use the PublishedRequest.PublishedContent property on the UmbracoContext. That should also give you the current page.huwred
09/05/2023, 2:27 PMhuwred
09/05/2023, 2:42 PMcsharp
public class SearchViewModel : PublishedContentWrapped
{
public string query { get; set; }
public string searchIn { get; set; }
public long TotalResults { get; set; }
public IEnumerable<IPublishedContent> PagedResult { get; set; }
public SearchViewModel(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback)
{
}
}
huwred
09/05/2023, 2:43 PM@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<SearchViewModel>
huwred
09/05/2023, 2:47 PMcsharp
public class SearchPageController : RenderController
{
private readonly IPublishedContentQuery _publishedContentQuery;
private readonly IExamineManager _examineManager;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly ServiceContext _serviceContext;
public SearchPageController(ILogger<SearchPageController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor, IVariationContextAccessor variationContextAccessor, ServiceContext context,IPublishedContentQuery publishedContentQuery,IExamineManager examineManager)
: base(logger, compositeViewEngine, umbracoContextAccessor)
{
_variationContextAccessor = variationContextAccessor;
_serviceContext = context;
_publishedContentQuery = publishedContentQuery;
_examineManager = examineManager;
}
public override IActionResult Index()
{
SearchViewModel searchPageViewModel = new SearchViewModel(CurrentPage,
new PublishedValueFallback(_serviceContext, _variationContextAccessor))
{
//do the search
query = "",
searchIn = "",
TotalResults = 0,
PagedResult = null
};
// return our custom ViewModel
return CurrentTemplate(searchPageViewModel);
}
}
You can view the whole code here
https://github.com/huwred/MediaWizForumsPascalEugster
09/06/2023, 7:23 AM