RenderPage - JimBobSquarePants/Zoombraco GitHub Wiki

RenderPage<T>

The generic RenderPage<T> class is the default wrapper for rendering our strong typed models within an MVC view. It implements the following interface.

/// <summary>
/// Encapsulates properties required rendering pages with metadata.
/// </summary>
/// <typeparam name="T">
/// The type of object to create the render model for.
/// </typeparam>
public interface IRenderPage<out T>
    where T : Page
{
    /// <summary>
    /// Gets the content.
    /// </summary>
    T Content { get; }

    /// <summary>
    /// Gets the culture.
    /// </summary>
    CultureInfo CurrentCulture { get; }
}

The generic nature of this class allows its reuse for different models. For results where you wish to combine several models into a single viewmodel inherit this class as follows.

/// <summary>
/// The render model for the home page document type.
/// </summary>
public class RenderHome : RenderPage<Home>
{
    /// <summary>
    /// Initializes a new instance of the <see cref="RenderHome" /> class.
    /// </summary>
    /// <param name="content">The <see cref="T:System.Type" /> to create the view model from.</param>
    /// <param name="culture">
    /// The <see cref="T:System.Globalization.CultureInfo" /> providing information about the specific culture.
    /// </param>
    public RenderHome(Home content, CultureInfo culture)
        : base(content, culture)
    {
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="RenderHome" /> class.
    /// </summary>
    /// <param name="content">The <see cref="T:System.Type" /> to create the view model from.</param>
    public RenderHome(Home content)
        : base(content)
    {
    }

    /// <summary>
    /// Gets or sets the latest articles
    /// </summary>
    public ICollection<IArticle> LatestArticles { get; set; } = new HashSet<IArticle>();
}
⚠️ **GitHub.com Fallback** ⚠️