Files
Umbraco-CMS/src/Umbraco.Web/Models/RenderModel.cs
Shannon Deminick 7df9921441 Fixes: #U4-1142, Changed ctor for RenderModel so people can actually create one to pass in to their views if they want.
Changed the way that UmbracoTemplatePage works in that if you pass in an IPublishedContent model instead of a RenderModel,
it will be generated for you without a YSOD. Changed the UmbracoHelper ctor so that it can be passed a custom IPublishedContent model
so that it's context is of that model and not the one routed to. Added Umbraco.Web.Mvc to the imported namespaces for Views.
2012-11-05 11:27:28 +06:00

50 lines
1.6 KiB
C#

using System;
using System.Globalization;
using Umbraco.Core.Models;
namespace Umbraco.Web.Models
{
/// <summary>
/// Represents the model for the current rendering page in Umbraco
/// </summary>
public class RenderModel
{
/// <summary>
/// Constructor specifying both the IPublishedContent and the CultureInfo
/// </summary>
/// <param name="content"></param>
/// <param name="culture"></param>
public RenderModel(IPublishedContent content, CultureInfo culture)
{
if (content == null) throw new ArgumentNullException("content");
if (culture == null) throw new ArgumentNullException("culture");
Content = content;
CurrentCulture = culture;
}
/// <summary>
/// Constructor to set the IPublishedContent and the CurrentCulture is set by the UmbracoContext
/// </summary>
/// <param name="content"></param>
public RenderModel(IPublishedContent content)
{
if (content == null) throw new ArgumentNullException("content");
if (UmbracoContext.Current == null)
{
throw new InvalidOperationException("Cannot construct a RenderModel without specifying a CultureInfo when no UmbracoContext has been initialized");
}
Content = content;
CurrentCulture = UmbracoContext.Current.PublishedContentRequest.Culture;
}
/// <summary>
/// Returns the current IPublishedContent object
/// </summary>
public IPublishedContent Content { get; private set; }
/// <summary>
/// Returns the current Culture assigned to the page being rendered
/// </summary>
public CultureInfo CurrentCulture { get; private set; }
}
}