diff --git a/src/Umbraco.Web/Mvc/RenderModelBinder.cs b/src/Umbraco.Web/Mvc/RenderModelBinder.cs
index 20045604d0..172befb791 100644
--- a/src/Umbraco.Web/Mvc/RenderModelBinder.cs
+++ b/src/Umbraco.Web/Mvc/RenderModelBinder.cs
@@ -7,8 +7,8 @@ using Umbraco.Web.Models;
namespace Umbraco.Web.Mvc
{
- public class RenderModelBinder : IModelBinder
- {
+ public class RenderModelBinder : IModelBinder, IModelBinderProvider
+ {
///
/// Binds the model to a value by using the specified controller context and binding context.
///
@@ -18,14 +18,13 @@ namespace Umbraco.Web.Mvc
/// The controller context.The binding context.
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
- if (bindingContext.ModelType != typeof (RenderModel)) return null;
-
object model;
if (controllerContext.RouteData.DataTokens.TryGetValue("umbraco", out model) == false)
return null;
- return model as RenderModel;
- }
+ var culture = UmbracoContext.Current.PublishedContentRequest.Culture;
+ return BindModel(model, bindingContext.ModelType, culture);
+ }
// source is the model that we have
// modelType is the type of the model that we need to bind to
@@ -103,5 +102,18 @@ namespace Umbraco.Web.Mvc
throw new ModelBindingException(string.Format("Cannot bind source type {0} to model type {1}.",
sourceType, modelType));
}
+
+ public IModelBinder GetBinder(Type modelType)
+ {
+ // can bind to RenderModel
+ if (modelType == typeof(RenderModel)) return this;
+
+ // can bind to RenderModel
+ if (modelType.IsGenericType && modelType.GetGenericTypeDefinition() == typeof(RenderModel<>)) return this;
+
+ // can bind to TContent where TContent : IPublishedContent
+ if (typeof(IPublishedContent).IsAssignableFrom(modelType)) return this;
+ return null;
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs
index d2f7910e5c..1034d33297 100644
--- a/src/Umbraco.Web/WebBootManager.cs
+++ b/src/Umbraco.Web/WebBootManager.cs
@@ -135,7 +135,7 @@ namespace Umbraco.Web
ViewEngines.Engines.Add(new PluginViewEngine());
//set model binder
- ModelBinders.Binders.Add(new KeyValuePair(typeof(RenderModel), new RenderModelBinder()));
+ ModelBinderProviders.BinderProviders.Add(new RenderModelBinder()); // is a provider
////add the profiling action filter
//GlobalFilters.Filters.Add(new ProfilingActionFilter());