If this was possible within the Hybrid Framework it would be one step closer to Umbraco development nirvana..
Bit of background - I have the framework building against v7.2 and I am using DocType compositions for my site structure. Stephan's amazing ModelsBuilder is doing a great job creating interfaces for these compositions and ensuring doctypes which include them implement the interface. For example, I have a composition, 'Sidebar' which contains a widget picker. This composition is included on the 'Home' doctype (among others) and therefore the Home generated class implements ISidebar. So far so good.
What's not working is passing this interface or generated class as the type of MasterModel to the View, e.g.
This results in an error like: The model item passed into the dictionary is of type MasterModel'[Home], but this dictionary requires a model item of type MasterModel'[Sidebar].
Do you think this is achievable? I have worked around the issue by creating a property on the MasterModel but it would be SUPER AWESOME if this wasnt necessary.
EDIT: I ensured MasterModel also implemented the interface, but no joy. I'm not that familiar with using interfaces so I'm hopefully overlooking somehting.
public class MasterModel : RenderModel, IMasterModel
where T : class, ISidebar, IPublishedContent
I did some experimenting with DocType compositions myself. Can't you just pass the model that inherits all those interfaces? Why would you only want to pass an interface?
Ah yes, forgot that bit. Because my layout view structure is Master - Sidebar - Home. Sidebar will be the layout for multiple views, so I was hoping it would work in a similar way that you can pass an interface or class to Model.Content.Children<T>() to filter the results.
I guess I am just being a bit lazy and I should implement a SidebarModel that can be included/inherited in the top-level classes that need it - I was just wondering if it could be done with the structure provided by the ModelsBuilder alone. Or just get property values the old fashioned way in that particular layout (boo!)
Keep up the great work! Umbraco 7.2 + Hybrid Framework rocks
Ran into this today. Did anyone find some sort of solution?
In my case, I've found three occasions when this issue occurs (in the most annoying order ;-)):
1) When I want to pass the model to a partial view that is included on various templates
2) When I need to access model properties in a template's parent template (using layout = ...)
3) When I want to document type to be rendered using an alternate template that can also be used got another document type.
It must be somehow possible to let the view be a little less restrictive on the model that's passed into it ;-)
I asked a similar question, where I wanted to convert different nodes which all use composition "FeaturedImage". However, I still haven't heard of a way to do this but it might be included in the next update for Hybrid.
The best way I have found for dealing with this situation is to use a partial view, creating a surface controller, where I create a custom model and send this to the partial view.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Extensions.Models.Generated;
namespace Umbraco.Extensions.Models.Custom
{
public class BookPopupPartial
{
public Image BackgroundImage { get; set; }
public String Title { get; set; }
public IHtmlString Terms { get; set; }
public UrlPicker.Umbraco.Models.UrlPicker TicketLink { get; set; }
public IPublishedContent TermsLink { get; set; }
}
}
and finally the SurfaceRenderMvcController:
using System.Web;
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Extensions.Controllers.Base;
using Umbraco.Extensions.BLL;
using Umbraco.Extensions.Enums;
using Umbraco.Extensions.Models;
using Umbraco.Extensions.Models.Custom;
using Umbraco.Extensions.Models.Generated;
using Umbraco.Extensions.Utilities;
using Umbraco.Web;
namespace Umbraco.Extensions.Controllers
{
public class BookPopupController : SurfaceRenderMvcController
{
[ChildActionOnly]
public ActionResult GetBookPopup()
{
var model = new BookPopupPartial()
{
BackgroundImage = CurrentPage.GetPropertyValue<Image>("image"),
Title = CurrentPage.GetPropertyValue<String>("title"),
Terms = CurrentPage.GetPropertyValue<IHtmlString>("terms"),
TicketLink = CurrentPage.GetPropertyValue<UrlPicker.Umbraco.Models.UrlPicker>("ticketLink"),
TermsLink = CurrentPage.GetPropertyValue<IPublishedContent>("termLink"),
};
return PartialView("book-popup", model);
}
}
}
This is how I have been doing it recently and means I can easily reuse the partial when ever a page uses this composition.
The model item passed into the dictionary is of type 'ContentModels.MasterContentModel`1[ContentModels.NewsContentModel]', but this dictionary requires a model item of type 'ContentModels.MasterContentModel`1[ContentModels.INewsContentModel]'.
Passing MasterModel<Interface> to a view
If this was possible within the Hybrid Framework it would be one step closer to Umbraco development nirvana..
Bit of background - I have the framework building against v7.2 and I am using DocType compositions for my site structure. Stephan's amazing ModelsBuilder is doing a great job creating interfaces for these compositions and ensuring doctypes which include them implement the interface. For example, I have a composition, 'Sidebar' which contains a widget picker. This composition is included on the 'Home' doctype (among others) and therefore the Home generated class implements ISidebar. So far so good.
What's not working is passing this interface or generated class as the type of MasterModel to the View, e.g.
This results in an error like: The model item passed into the dictionary is of type MasterModel'[Home], but this dictionary requires a model item of type MasterModel'[Sidebar].
Do you think this is achievable? I have worked around the issue by creating a property on the MasterModel but it would be SUPER AWESOME if this wasnt necessary.
EDIT: I ensured MasterModel also implemented the interface, but no joy. I'm not that familiar with using interfaces so I'm hopefully overlooking somehting.
I did some experimenting with DocType compositions myself. Can't you just pass the model that inherits all those interfaces? Why would you only want to pass an interface?
Ah yes, forgot that bit. Because my layout view structure is Master - Sidebar - Home. Sidebar will be the layout for multiple views, so I was hoping it would work in a similar way that you can pass an interface or class to Model.Content.Children<T>() to filter the results.
I guess I am just being a bit lazy and I should implement a SidebarModel that can be included/inherited in the top-level classes that need it - I was just wondering if it could be done with the structure provided by the ModelsBuilder alone. Or just get property values the old fashioned way in that particular layout (boo!)
Keep up the great work! Umbraco 7.2 + Hybrid Framework rocks
I'm struggling with this in my head too.
Ran into this today. Did anyone find some sort of solution?
In my case, I've found three occasions when this issue occurs (in the most annoying order ;-)): 1) When I want to pass the model to a partial view that is included on various templates 2) When I need to access model properties in a template's parent template (using layout = ...) 3) When I want to document type to be rendered using an alternate template that can also be used got another document type.
It must be somehow possible to let the view be a little less restrictive on the model that's passed into it ;-)
Hi,
I asked a similar question, where I wanted to convert different nodes which all use composition "FeaturedImage". However, I still haven't heard of a way to do this but it might be included in the next update for Hybrid.
The best way I have found for dealing with this situation is to use a partial view, creating a surface controller, where I create a custom model and send this to the partial view.
Top of Partial:
the custom Model:
and finally the SurfaceRenderMvcController:
This is how I have been doing it recently and means I can easily reuse the partial when ever a page uses this composition.
Hopefully this is helpful
Thanks
Maxi
Ran into the issue today (again) when I want to use a single template for two documenttypes.
Creating an interface that bind the two documenttypes didn't work unfortunately.
This throws an InvalidOperationException
Did anyone find a workable solution for this?
is working on a reply...