Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Nov 13, 2016 @ 15:25
    Paul Griffiths
    0

    Model object is null question

    Hi all,

    Can some please help explain something? I’m messing around with surface controllers and i'm clearing missing something.

    I have the following Homepage razor view which has a bunch of partial defined and one html.action call.

    enter image description here

    The Html.Action calls the following custom controller which I have defined

    enter image description here

    At this point all the controller does is make a call to the following partial

    enter image description here

    If I call the partial directly from the home page then the Model.Content is available. However, if i call it from the controller i get the Model is null.

    What do i need to do?

    Paul

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Nov 14, 2016 @ 07:41
    Dave Woestenborghs
    100

    Hi Paul,

    I think the problem is that you are not passing your model to your view in your action.

    You can do this in our action :

    public ActionResult Index()
    {
        var siteRoot = this.Umbraco.AssignedContentItem.AncestorOrSelf("homePage");
        var testimonialPage = siteRoot.Descendant("testimonialPage");
        return PartialView("Homepage/TestimonialsSection", testimonialPage)
    }
    

    And then your first line in your view should be :

    @inherits UmbracoViewPage<IPublishedContent>
    

    Now your model in your view is the content item of the testimonialpage.

    Dave

    PS : I'm writing this from the train without testing, so there can be some syntax errors

    Dave

  • Paul Griffiths 370 posts 1021 karma points
    Nov 15, 2016 @ 13:33
    Paul Griffiths
    0

    Hi Dave,

    Thanks very much for responding. It makes sense what you are saying.

    Ill have have a play around and see if i can get it working :)

    Will let you know

    Paul

  • 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.

Please Sign in or register to post replies