view src/Web/RazorEngine.Mvc/MvcTemplateBase.cs @ 2:b0419fdcff0b

Правка зависимостей
author Andre K <m407@mail.ru>
date Sat, 13 Dec 2014 18:14:19 +0300
parents 5bca2d201ad8
children
line wrap: on
line source

namespace RazorEngine.Mvc
{
    using System;
    using System.Web;
    using System.Web.Mvc;

    using Templating;

    /// <summary>
    /// Provides a base implementation of an MVC-compatible template.
    /// </summary>
    public abstract class MvcTemplateBase : TemplateBase
    {
        #region Properties
        /// <summary>
        /// Gets the <see cref="HtmlHelper{Object}"/> for this template.
        /// </summary>
        public HtmlHelper<object> Html { get; private set; }

        /// <summary>
        /// Gets the <see cref="UrlHelper"/> for this template.
        /// </summary>
        public UrlHelper Url { get; private set; }
        #endregion

        #region Methods
        public void InitHelpers()
        {
            var httpContext = new HttpContextWrapper(HttpContext.Current);
            var handler = httpContext.CurrentHandler as MvcHandler;
            if (handler == null)
                throw new InvalidOperationException("Unable to run template outside of ASP.NET MVC");
        }
        #endregion
    }
}