Anyone know what is the equivalent to the "RenderModel model" parameter in version 8 that needs to be passed in to a controller action?
I'm using "ContentModel" at the moment and I can get the content I've mapped the request to. However, "model.Url" throws an error:
((Umbraco.Core.Models.PublishedContent.PublishedContentWrapped)item).Url' threw an exception of type 'System.ArgumentException
Controller action:
public ActionResult Index(ContentModel model, string performername, string section)
{
Performer performer = PerformerService.GetPerformer(performername);
var viewModel = new PerformerViewModel(model.Content);
this.SetViewModel(viewModel, performer, section);
//var url = model.Content.Url; --> this throws the error above
return CurrentTemplate(viewModel);
}
I've mapped the route using RouteTable.Routes.MapUmbracoRoute (and implemented a UmbracoVirtualNodeRouteHandler.
ContentModel is the correct thing to have, and it's the job of the UmbracoVirtualNodeRouteHandler to return the IPublishedContent item that will be associated with the root.
I've just spun up a quick test in V8, and I'm finding the model is populated and the Url is being returned without error:
I'm using the core UmbracoVirtualNodeByIdRouteHandler that takes the Id of the content item you want to associate, here 1105 is the Products node in the starter kit
public void Initialize()
{
RouteTable.Routes.MapUmbracoRoute("ProductCustomRoute", "products2/{action}/{id}", new
{
controller = "SuperProduct",
id = UrlParameter.Optional
}, new UmbracoVirtualNodeByIdRouteHandler(1105));
}
so maybe the issue is inside your implementation of the VirtualNodeRouteHandler?
eg is that definately finding and returning a published content item?
thanks for checking and confirming this.
My implementation of VirtualNodeRouteHandler is simple and it returns the content the request is mapped to:
public class PerformerNodeRouteHandler : UmbracoVirtualNodeRouteHandler
{
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext)
{
var performerPage = umbracoContext.ContentCache.GetAtRoot().First().Descendant<Performer>();
return performerPage;
}
}
I've also tried your approach using UmbracoVirtualNodeByIdRouteHandler directly in "MapUmbracoRoute" with the same result.
I thought it maybe something to do with the fact I've moved my models to a separate project so I moved them back to the web project (App_Data) folder - that didn't help either. My current config is:
If you set a breakpoint on your return performerPage; line in your VirtualNodeRouteHandler, and the scenario reoccurs, is the Url property also null on the performerPage object?
eg trying to work out if all is ok with the VirtualNodeRouteHandling + MapUmbracoRoute, or whether the issue lies with your published cache somehow... hmmm
this is resolved now. I made two changes so unfortunately cannot pinpoint this to a specific one. What I did was upgrade to CMS 8.0.1 & ModelsBuilder 8.0.4 (both my web and entities projects).
I also changed the way my Entities project was referencing Umbraco dlls - previously I had simply added references to Umbraco CMS & ModelsBuilder, pointing to the relevant packages:
Now that I'm managing these through NuGet for the Entities project, it has resulted in NuGet pulling quite a few more dependencies, so I am inclined to thing it's the latter.
Custom routes - parameter for Controller action
Hi,
Anyone know what is the equivalent to the "RenderModel model" parameter in version 8 that needs to be passed in to a controller action? I'm using "ContentModel" at the moment and I can get the content I've mapped the request to. However, "model.Url" throws an error:
Controller action:
I've mapped the route using RouteTable.Routes.MapUmbracoRoute (and implemented a UmbracoVirtualNodeRouteHandler.
Hi Ross
ContentModel is the correct thing to have, and it's the job of the UmbracoVirtualNodeRouteHandler to return the IPublishedContent item that will be associated with the root.
I've just spun up a quick test in V8, and I'm finding the model is populated and the Url is being returned without error:
I'm using the core UmbracoVirtualNodeByIdRouteHandler that takes the Id of the content item you want to associate, here 1105 is the Products node in the starter kit
so maybe the issue is inside your implementation of the VirtualNodeRouteHandler?
eg is that definately finding and returning a published content item?
Hi Marc,
thanks for checking and confirming this. My implementation of VirtualNodeRouteHandler is simple and it returns the content the request is mapped to:
I've also tried your approach using UmbracoVirtualNodeByIdRouteHandler directly in "MapUmbracoRoute" with the same result.
I thought it maybe something to do with the fact I've moved my models to a separate project so I moved them back to the web project (App_Data) folder - that didn't help either. My current config is:
The strange thing is that in between builds I can get this to work, however if the app pool recycles (or I force it to), it will start to fail..
Hi Ross
That does sound strange.
If you set a breakpoint on your return performerPage; line in your VirtualNodeRouteHandler, and the scenario reoccurs, is the Url property also null on the performerPage object?
eg trying to work out if all is ok with the VirtualNodeRouteHandling + MapUmbracoRoute, or whether the issue lies with your published cache somehow... hmmm
regards
Marc
Hi Marc,
this is resolved now. I made two changes so unfortunately cannot pinpoint this to a specific one. What I did was upgrade to CMS 8.0.1 & ModelsBuilder 8.0.4 (both my web and entities projects).
I also changed the way my Entities project was referencing Umbraco dlls - previously I had simply added references to Umbraco CMS & ModelsBuilder, pointing to the relevant packages:
Now that I'm managing these through NuGet for the Entities project, it has resulted in NuGet pulling quite a few more dependencies, so I am inclined to thing it's the latter.
Thanks for you help. Ross
is working on a reply...