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
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:
RenderModel(content)
[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?
UmbracoContext.Current.PublishedContentRequest
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.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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:
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:
The exception comes from the call to
RenderModel(content)
which is throwing a NullReferenceException:Looking at the source it appears that we have a problem with
UmbracoContext.Current.PublishedContentRequest
being unset. Is there a way around this?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.
is working on a reply...