Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello,
When i call a partial it complains the Model isn't IPublishedContent?
But when i tell my custom ViewModel to inherit from IPublishedContent like in the documentation, i get the following error:
Err: 'No parameterless constructor defined for this object.'
How do i fix this so i can use my partials?
Code below:
ViewModel:
public class MainViewModel : ContentModel { //Constructor of MainViewModel public MainViewModel(IPublishedContent content) : base(content) { SiteSettings = new SiteSettingsViewModel(); BusinessCentersData = new List<BusinessCenterDataViewModel>(); BusinessCenterData = new BusinessCenterDataViewModel(); SiteSettings = new SiteSettingsViewModel(); UmbracoBusinessCenters = new UmbracoBusinessCentersViewModel(); RawContent = RawContent; } //Independant View public SiteSettingsViewModel SiteSettings { get; set; } public UmbracoBusinessCentersViewModel UmbracoBusinessCenters { get; set; } public List<BusinessCenterDataViewModel> BusinessCentersData { get; set; } public BusinessCenterDataViewModel BusinessCenterData { get; set; } public IPublishedContent RawContent {get; private set; } public string siteName { get; set; } public dynamic RootNode { get; set; } }
Controller:
public ActionResult BusinessCenters(MainViewModel model) { try { using (var cref = _context.EnsureUmbracoContext()) { //Content Cache //var cache = cref.UmbracoContext.Content; var cache = cref.UmbracoContext.Content; dynamic rootNode = cache.GetAtRoot(); model.RootNode = rootNode; //Call Any Missing Umbraco Content IPublishedContent siteSettings = cache.GetSingleByXPath("//siteSettings"); UmbracoContentBuilderClass siteSettingsModel = new UmbracoContentBuilderClass(); model.SiteSettings = siteSettingsModel.PopulateSiteSettingsModel(siteSettings); IPublishedContent businessCenters = cache.GetSingleByXPath("//businessCenters"); UmbracoContentBuilderClass businessCentersModel = new UmbracoContentBuilderClass(); model.UmbracoBusinessCenters = businessCentersModel.PopulateBusinessCentersModel(businessCenters); } return PartialView("~/Views/thejourney/firstpage.cshtml", model); } catch (Exception e) { CustomLogger.Error($"ERROR: BusinessCenterListingsController.BusinessCenters (GET) {e}"); throw; }
Partial:
@inherits UmbracoViewPage<officefreedom.AppCode.ViewModels.MainViewModel> <div class="upper-nav-container col-xs-12 col-md-12"> @Html.Partial("~/Views/Partials/_Navigation.cshtml", Model.RawContent)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Extending Umbraco with custom controller and routing
Hello,
When i call a partial it complains the Model isn't IPublishedContent?
But when i tell my custom ViewModel to inherit from IPublishedContent like in the documentation, i get the following error:
Err: 'No parameterless constructor defined for this object.'
How do i fix this so i can use my partials?
Code below:
ViewModel:
Controller:
Partial:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.