Copied to clipboard

Flag this post as spam?

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


  • glenatron 37 posts 132 karma points
    Dec 27, 2013 @ 15:52
    glenatron
    1

    Cannot create a RenderModel from a node queried from the UmbracoHelper?

    I am working on an MVC site built with Umbraco and I've hit a slightly odd problem where I have an action that looks like this:

    public ActionResult Story(int Id, string Name)
        {
            UmbracoHelper queryMe = new UmbracoHelper(UmbracoContext.Current);
            IPublishedContent story = queryMe.TypedContent(Id);
            NewsStoryViewModel storyView = new NewsStoryViewModel(story);
            return base.Index((RenderModel)storyView);
        }
    

    When this is called, the Id is set, the helper locates the IPublishedContent and then it crashes on the creation of the ViewModel.

    The ViewModel looks like this:

    public NewsStoryViewModel : RenderModel
      {
         public void NewsStoryViewModel(IPublishedContent content) : base(content)
             {
                 // do some stuff
             }
      }
    

    The exception comes from the call to RenderModel(content) which is throwing a NullReferenceException:

      [NullReferenceException: Object reference not set to an instance of an object.]
      Umbraco.Web.Models.RenderModel..ctor(IPublishedContent content) +47
    

    Looking at the source it appears that we have a problem with UmbracoContext.Current.PublishedContentRequest being unset. Is there a way around this?

  • glenatron 37 posts 132 karma points
    Dec 27, 2013 @ 17:29
    glenatron
    0

    Ah, the answer is in this thread - if you're not using Index() then the Umbraco request handling is bypassed entirely.

    I'm amazed by just how difficult it is to go from regular Asp.Net MVC to Umbraco MVC development.

Please Sign in or register to post replies

Write your reply to:

Draft