Model does not get resolved when using SurfaceControllers
Hi!
I am using Ditto, and it works very well with my regular pagecontrollers.
However, I stumbled into a problem when trying retrieve pages using a SurfaceController.
I Have a code for retrieving Children by type, that looks something like this:
public IEnumerable<T> GetChildren<T>(int pageId) where T : class
{
var page = new UmbracoHelper(UmbracoContext.Current).TypedContent(pageId);
return page.Children.Where(x => x is T).As<T>().ToList();
}
With regular page controllers this function works very well. and I only get the children that is of the Type T.
var children = GetChildren<CoursePage>(1073);
When calling this function from a surfacecontroller, it does not recognize the pagetypes. None of the children is of Type T, and I get an empty list.
The same thing happens when trying to get one page. I get the page, but it is not resolved as my model when using a SurfaceController.
var page = new UmbracoHelper(UmbracoContext.Current).TypedContent(1073);
I am pretty new with umbraco (and ditto), so maybe I am doing something completely wrong here..
Yes, I am using the DittoModelFactory, and using Ditto 0.7.0.
I'll try to explain a little easier:
This is a regular PageController:
public override ActionResult Index(RenderModel model)
{
if (model.Content is CoursePage)
{
//YES, This works. model.Content is of the type CoursePage
}
var page = new UmbracoHelper(UmbracoContext.Current).TypedContent(1074);
if (page is CoursePage)
{
//This also works, because 1074 is a CoursePage
}
Everyting works!
Now, if I try this in a SurfaceController, it does not work.
I get the page, but it is not resolved as a CoursePage.
public PartialViewResult Search()
{
var page = new UmbracoHelper(UmbracoContext.Current).TypedContent(1074);
//This does not work in a surfaceController. page is not resolved as CoursePage
if (page is CoursePage)
{
}
But I don't think this is the same problem. I have no issues with casting the page to a CoursePage. (So the culture issue is probably fixed :) )
What i am trying to do is figure out if the page Actually is a CoursePage.
Right now I have a ugly workaround, comparing the ContentType.Alias with the PublishedContentModel attribute. But this does of course not work with Interfaces etc..
Ah doh! I forgot about the model-factory setup, (it's Monday morning, I'm not fully awake yet) ;-)
There must be some kind of Umbraco context missing (or not being set) when using a SurfaceController, (either a bug or intentional in the Umbraco core)?
To be honest, I'm not 100% happy Ditto's model-factory implementation... I never use it myself - it was written as a prototype and released for if/when people wanted to contribute to it. So unfortunately I can't give much support for it :-(
Depending on how comfortable you are with open-source stuff, please do feel free to grab the source-code and try debugging the DittoPublishedContentModelFactory.
I'm totally happy to chat over it, (I just don't have a solution/fix for you)
Model does not get resolved when using SurfaceControllers
Hi!
I am using Ditto, and it works very well with my regular pagecontrollers. However, I stumbled into a problem when trying retrieve pages using a SurfaceController.
I Have a code for retrieving Children by type, that looks something like this:
With regular page controllers this function works very well. and I only get the children that is of the Type T.
When calling this function from a surfacecontroller, it does not recognize the pagetypes. None of the children is of Type T, and I get an empty list.
The same thing happens when trying to get one page. I get the page, but it is not resolved as my model when using a SurfaceController.
I am pretty new with umbraco (and ditto), so maybe I am doing something completely wrong here..
Does anyone have any idea of how to solve this?
Thanks, Espen
Hi Espen,
Sorry, I don't completely follow what your set-up is.
Are you using the DittoModelFactory? (or another model-factory?)
I'm trying to understand where the
CoursePage
type comes into play.... and just to check, is this Ditto v0.7.0?
Thanks,
- Lee
Hi!
Yes, I am using the DittoModelFactory, and using Ditto 0.7.0.
I'll try to explain a little easier:
This is a regular PageController:
Everyting works!
Now, if I try this in a SurfaceController, it does not work.
I get the page, but it is not resolved as a CoursePage.
Was this understandable ? I Get
Thanks, Espen
Hi Espen,
Take a look the solution on this thread...
https://our.umbraco.org/projects/developer-tools/ditto/ditto-feedback/65056-Ditto-As-returning-null-in-controller-called-through-an-Ajax-call
It's worth a try.
I'm not 100% convinced that this will fix your issue (with SurfaceControllers), as we add a patch for the
culture
issue in v0.7.0.Let me know if it works for you or not.
Cheers,
- Lee
Thanks!
But I don't think this is the same problem. I have no issues with casting the page to a CoursePage. (So the culture issue is probably fixed :) )
What i am trying to do is figure out if the page Actually is a CoursePage.
Right now I have a ugly workaround, comparing the ContentType.Alias with the PublishedContentModel attribute. But this does of course not work with Interfaces etc..
Espen
Hi Espen,
Ah doh! I forgot about the model-factory setup, (it's Monday morning, I'm not fully awake yet) ;-)
There must be some kind of Umbraco context missing (or not being set) when using a SurfaceController, (either a bug or intentional in the Umbraco core)?
To be honest, I'm not 100% happy Ditto's model-factory implementation... I never use it myself - it was written as a prototype and released for if/when people wanted to contribute to it. So unfortunately I can't give much support for it :-(
Depending on how comfortable you are with open-source stuff, please do feel free to grab the source-code and try debugging the
DittoPublishedContentModelFactory
.I'm totally happy to chat over it, (I just don't have a solution/fix for you)
Cheers,
- Lee
OK! Thanks!
I'll do some digging to see if I can solve this...
is working on a reply...