41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using System;
|
|
using Microsoft.AspNet.Abstractions;
|
|
|
|
namespace Microsoft.AspNet.Mvc.Rendering
|
|
{
|
|
public class HtmlHelper<TModel> : HtmlHelper, IHtmlHelper<TModel>
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="HtmlHelper{TModel}"/> class.
|
|
/// </summary>
|
|
public HtmlHelper(IViewEngine viewEngine)
|
|
: base(viewEngine)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public new ViewDataDictionary<TModel> ViewData { get; private set;}
|
|
|
|
public override void Contextualize([NotNull] ViewContext viewContext)
|
|
{
|
|
if (viewContext.ViewData == null)
|
|
{
|
|
throw new ArgumentException(Resources.FormatArgumentPropertyNull("ViewData"), "viewContext");
|
|
}
|
|
|
|
ViewData = viewContext.ViewData as ViewDataDictionary<TModel>;
|
|
if (ViewData == null)
|
|
{
|
|
// viewContext may contain a base ViewDataDictionary instance. So complain about that type, not TModel.
|
|
throw new ArgumentException(Resources.FormatArgumentPropertyUnexpectedType(
|
|
"ViewData",
|
|
viewContext.ViewData.GetType().FullName,
|
|
typeof(ViewDataDictionary<TModel>).FullName),
|
|
"viewContext");
|
|
}
|
|
|
|
base.Contextualize(viewContext);
|
|
}
|
|
}
|
|
}
|