Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Christina 127 posts 390 karma points notactivated
    Apr 30, 2018 @ 15:16
    Christina
    0

    Hi I'm creating a simple list like a bloglist that get content from subpages. Blog -subplage1 -subpage2 ... I have created surfacecontroller and i get an error in the Template @{Html.RenderAction("RenderPuffInfoList", "SiteLayout");}

    Can someone help me, thanks! /C

    A Partial View @model IEnumerable

    @foreach (PuffInfoItem item in Model) { @RenderPuffInfo(item) }

    A Controller public class TemaController: SurfaceController { private const string PARTIALVIEWFOLDER = "~/Views/Partials/SiteLayout/";

        public ActionResult RenderPuffInfoList()
        {
            List<PuffInfoItem> puff = new List<PuffInfoItem>();
            var siteComp = Umbraco.AssignedContentItem.Children().Where(m => m.DocumentTypeAlias == "Tema");
    
            foreach (IPublishedContent page in siteComp)
            {
                string _Header = page.GetPropertyValue("rubrik").ToString();
                string _Image = page.GetPropertyValue("puffImage").ToString();
                string _Ingress = page.GetPropertyValue("puffIngress").ToString();
                string _Url = page.GetPropertyValue("puffButton").ToString();
                string _Color = page.GetPropertyValue("puffColor").ToString();
                puff.Add(new PuffInfoItem(_Header, _Image, _Ingress, _Url,_Color));
            }
                 return PartialView(viewName: PARTIAL_VIEW_FOLDER + "_Tema_Puffs.cshtml",model:puff);
        }
    }
    

    A Model public class PuffInfoItem { public string Header { get; set; } public string Image { get; set; } public string Ingress { get; set; } public string Url { get; set; } public string Color { get; set; }

        public PuffInfoItem(string header, string image, string ingress, string url, string color)
        {
            Header = header;
            Image = image;
            Ingress = ingress;
            Url = url;
            Color = color;
        }       
    }
    
  • Nigel Wilson 944 posts 2076 karma points
    Apr 30, 2018 @ 16:52
    Nigel Wilson
    0

    Hi Christina

    What is the error you are getting ?

    Nigel

  • Christina 127 posts 390 karma points notactivated
    Apr 30, 2018 @ 18:04
    Christina
    0

    Hi and Thanks for helping me I got this error @{Html.RenderAction("RenderPuffInfoList", "SiteLayout");} Cannot create an instance of an interface.

    I have a "Root" node following treestructur. level(2)Home level(2)Blog level(3)-subpage1 level(3)-subpage2 level(2)ContactPage ...

    In the Controller i have IPublishedContent page as an argument And collection the subpages with: var pages = page.Children.Where(m => m.DocumentTypeAlias == "Tema"); Is that right? I'm an newbie in Umbraco and MVC /C

    public ActionResult RenderPuffInfoList(IPublishedContent page) { List

          var pages = page.Children.Where(m => m.DocumentTypeAlias == "Tema");
            foreach (IPublishedContent item in pages)
            {
                string _Header = page.GetPropertyValue("rubrik").ToString();
    
  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Apr 30, 2018 @ 21:57
    Nik
    0

    Hi Christina,

    I have a feeling, although I'm not 100%, but you cannot have a parameter to an action on a controller as an interface. The ModelsBinder that tries to bind your web request to an action needs to know what type to instantiate. It's an annoying error from MVC, as it allows you to compile the code but throws the error at runtime as you are seeing.

    If you need to pass a page to the controller, you are better off passing the page ID, and then retrieving the page in the controller.

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft