Reintroduce `IHtmlHelper` and use it everywhere possible

- no more `IHtmlHelper<object>` in `DefaultDisplayTemplates` and also no
  need for `ViewDataDictionary<object>` in a few places
- mostly removals from `IHtmlHelper<TModel>` but did cleanup comments and
  add `[NotNull]` for `DisplayFor()`, `DisplayNameFor()`,
  `DisplayNameForInnerType()`, and `LabelFor()`
- also add `[NotNull]` for `this` and `Expression` parameters in some
  extension methods
This commit is contained in:
dougbu 2014-04-25 22:49:00 -07:00
parent e21688ffb5
commit 66ca046135
22 changed files with 658 additions and 530 deletions

View File

@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Mvc
public IUrlHelper Url { get; set; } public IUrlHelper Url { get; set; }
public ViewDataDictionary<object> ViewData { get; set; } public ViewDataDictionary ViewData { get; set; }
public dynamic ViewBag public dynamic ViewBag
{ {

View File

@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Mvc
{ {
Injector.InjectProperty(controller, "ActionContext", actionContext); Injector.InjectProperty(controller, "ActionContext", actionContext);
var viewData = new ViewDataDictionary<object>( var viewData = new ViewDataDictionary(
_serviceProvider.GetService<IModelMetadataProvider>(), _serviceProvider.GetService<IModelMetadataProvider>(),
actionContext.ModelState); actionContext.ModelState);
Injector.InjectProperty(controller, "ViewData", viewData); Injector.InjectProperty(controller, "ViewData", viewData);

View File

@ -182,6 +182,7 @@
<Compile Include="Rendering\Html\TemplateRenderer.cs" /> <Compile Include="Rendering\Html\TemplateRenderer.cs" />
<Compile Include="Rendering\Html\ValidationHelpers.cs" /> <Compile Include="Rendering\Html\ValidationHelpers.cs" />
<Compile Include="Rendering\ICanHasViewContext.cs" /> <Compile Include="Rendering\ICanHasViewContext.cs" />
<Compile Include="Rendering\IHtmlHelper.cs" />
<Compile Include="Rendering\IHtmlHelperOfT.cs" /> <Compile Include="Rendering\IHtmlHelperOfT.cs" />
<Compile Include="Rendering\IView.cs" /> <Compile Include="Rendering\IView.cs" />
<Compile Include="Rendering\IViewEngine.cs" /> <Compile Include="Rendering\IViewEngine.cs" />

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class DefaultDisplayTemplates public static class DefaultDisplayTemplates
{ {
public static string BooleanTemplate(IHtmlHelper<object> html) public static string BooleanTemplate(IHtmlHelper html)
{ {
bool? value = null; bool? value = null;
if (html.ViewData.Model != null) if (html.ViewData.Model != null)
@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return inputTag.ToString(TagRenderMode.SelfClosing); return inputTag.ToString(TagRenderMode.SelfClosing);
} }
private static string BooleanTemplateDropDownList(IHtmlHelper<object> html, bool? value) private static string BooleanTemplateDropDownList(IHtmlHelper html, bool? value)
{ {
var selectTag = new TagBuilder("select"); var selectTag = new TagBuilder("select");
selectTag.AddCssClass("list-box"); selectTag.AddCssClass("list-box");
@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}; };
} }
public static string CollectionTemplate(IHtmlHelper<object> html) public static string CollectionTemplate(IHtmlHelper html)
{ {
var model = html.ViewData.ModelMetadata.Model; var model = html.ViewData.ModelMetadata.Model;
if (model == null) if (model == null)
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
public static string DecimalTemplate(IHtmlHelper<object> html) public static string DecimalTemplate(IHtmlHelper html)
{ {
if (html.ViewData.TemplateInfo.FormattedModelValue == html.ViewData.ModelMetadata.Model) if (html.ViewData.TemplateInfo.FormattedModelValue == html.ViewData.ModelMetadata.Model)
{ {
@ -169,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return StringTemplate(html); return StringTemplate(html);
} }
public static string EmailAddressTemplate(IHtmlHelper<object> html) public static string EmailAddressTemplate(IHtmlHelper html)
{ {
var uriString = "mailto:" + ((html.ViewData.Model == null) ? string.Empty : html.ViewData.Model.ToString()); var uriString = "mailto:" + ((html.ViewData.Model == null) ? string.Empty : html.ViewData.Model.ToString());
var linkedText = (html.ViewData.TemplateInfo.FormattedModelValue == null) ? var linkedText = (html.ViewData.TemplateInfo.FormattedModelValue == null) ?
@ -179,18 +179,18 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HyperlinkTemplate(uriString, linkedText); return HyperlinkTemplate(uriString, linkedText);
} }
public static string HiddenInputTemplate(IHtmlHelper<object> html) public static string HiddenInputTemplate(IHtmlHelper html)
{ {
// TODO: add ModelMetadata.HideSurroundingHtml and use here (return string.Empty) // TODO: add ModelMetadata.HideSurroundingHtml and use here (return string.Empty)
return StringTemplate(html); return StringTemplate(html);
} }
public static string HtmlTemplate(IHtmlHelper<object> html) public static string HtmlTemplate(IHtmlHelper html)
{ {
return html.ViewData.TemplateInfo.FormattedModelValue.ToString(); return html.ViewData.TemplateInfo.FormattedModelValue.ToString();
} }
public static string ObjectTemplate(IHtmlHelper<object> html) public static string ObjectTemplate(IHtmlHelper html)
{ {
var viewData = html.ViewData; var viewData = html.ViewData;
var templateInfo = viewData.TemplateInfo; var templateInfo = viewData.TemplateInfo;
@ -261,12 +261,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
!templateInfo.Visited(metadata); !templateInfo.Visited(metadata);
} }
public static string StringTemplate(IHtmlHelper<object> html) public static string StringTemplate(IHtmlHelper html)
{ {
return html.Encode(html.ViewData.TemplateInfo.FormattedModelValue); return html.Encode(html.ViewData.TemplateInfo.FormattedModelValue);
} }
public static string UrlTemplate(IHtmlHelper<object> html) public static string UrlTemplate(IHtmlHelper html)
{ {
var uriString = (html.ViewData.Model == null) ? string.Empty : html.ViewData.Model.ToString(); var uriString = (html.ViewData.Model == null) ? string.Empty : html.ViewData.Model.ToString();
var linkedText = (html.ViewData.TemplateInfo.FormattedModelValue == null) ? var linkedText = (html.ViewData.TemplateInfo.FormattedModelValue == null) ?

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <summary> /// <summary>
/// Default implementation of non-generic portions of <see cref="IHtmlHelper{T}">. /// Default implementation of non-generic portions of <see cref="IHtmlHelper{T}">.
/// </summary> /// </summary>
public class HtmlHelper : ICanHasViewContext public class HtmlHelper : IHtmlHelper, ICanHasViewContext
{ {
public static readonly string ValidationInputCssClassName = "input-validation-error"; public static readonly string ValidationInputCssClassName = "input-validation-error";
public static readonly string ValidationInputValidCssClassName = "input-validation-valid"; public static readonly string ValidationInputValidCssClassName = "input-validation-valid";
@ -52,8 +52,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
IdAttributeDotReplacement = "_"; IdAttributeDotReplacement = "_";
} }
/// <inheritdoc />
public string IdAttributeDotReplacement { get; set; } public string IdAttributeDotReplacement { get; set; }
/// <inheritdoc />
public ViewContext ViewContext public ViewContext ViewContext
{ {
get get
@ -71,6 +73,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
/// <inheritdoc />
public dynamic ViewBag public dynamic ViewBag
{ {
get get
@ -79,6 +82,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
/// <inheritdoc />
public ViewDataDictionary ViewData public ViewDataDictionary ViewData
{ {
get get
@ -89,6 +93,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
protected IModelMetadataProvider MetadataProvider { get; private set; } protected IModelMetadataProvider MetadataProvider { get; private set; }
/// <inheritdoc />
public HtmlString ActionLink( public HtmlString ActionLink(
[NotNull] string linkText, [NotNull] string linkText,
string actionName, string actionName,
@ -161,11 +166,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
ViewContext = viewContext; ViewContext = viewContext;
} }
/// <inheritdoc />
public HtmlString AntiForgeryToken() public HtmlString AntiForgeryToken()
{ {
return _antiForgeryInstance.GetHtml(ViewContext.HttpContext); return _antiForgeryInstance.GetHtml(ViewContext.HttpContext);
} }
/// <inheritdoc />
public MvcForm BeginForm(string actionName, string controllerName, object routeValues, FormMethod method, public MvcForm BeginForm(string actionName, string controllerName, object routeValues, FormMethod method,
object htmlAttributes) object htmlAttributes)
{ {
@ -179,37 +186,44 @@ namespace Microsoft.AspNet.Mvc.Rendering
return GenerateForm(actionName, controllerName, routeValues, method, htmlAttributeDictionary); return GenerateForm(actionName, controllerName, routeValues, method, htmlAttributeDictionary);
} }
/// <inheritdoc />
public void EndForm() public void EndForm()
{ {
var mvcForm = CreateForm(); var mvcForm = CreateForm();
mvcForm.EndForm(); mvcForm.EndForm();
} }
/// <inheritdoc />
public HtmlString CheckBox(string name, bool? isChecked, object htmlAttributes) public HtmlString CheckBox(string name, bool? isChecked, object htmlAttributes)
{ {
return GenerateCheckBox(metadata: null, name: name, isChecked: isChecked, htmlAttributes: htmlAttributes); return GenerateCheckBox(metadata: null, name: name, isChecked: isChecked, htmlAttributes: htmlAttributes);
} }
/// <inheritdoc />
public string Encode(string value) public string Encode(string value)
{ {
return (!string.IsNullOrEmpty(value)) ? WebUtility.HtmlEncode(value) : string.Empty; return (!string.IsNullOrEmpty(value)) ? WebUtility.HtmlEncode(value) : string.Empty;
} }
/// <inheritdoc />
public string Encode(object value) public string Encode(object value)
{ {
return value != null ? WebUtility.HtmlEncode(value.ToString()) : string.Empty; return value != null ? WebUtility.HtmlEncode(value.ToString()) : string.Empty;
} }
/// <inheritdoc />
public string FormatValue(object value, string format) public string FormatValue(object value, string format)
{ {
return ViewDataDictionary.FormatValue(value, format); return ViewDataDictionary.FormatValue(value, format);
} }
/// <inheritdoc />
public string GenerateIdFromName([NotNull] string name) public string GenerateIdFromName([NotNull] string name)
{ {
return TagBuilder.CreateSanitizedId(name, IdAttributeDotReplacement); return TagBuilder.CreateSanitizedId(name, IdAttributeDotReplacement);
} }
/// <inheritdoc />
public HtmlString Display(string expression, public HtmlString Display(string expression,
string templateName, string templateName,
string htmlFieldName, string htmlFieldName,
@ -223,6 +237,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
additionalViewData); additionalViewData);
} }
/// <inheritdoc />
public HtmlString DisplayForModel(string templateName, public HtmlString DisplayForModel(string templateName,
string htmlFieldName, string htmlFieldName,
object additionalViewData) object additionalViewData)
@ -232,7 +247,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
templateName, templateName,
additionalViewData); additionalViewData);
} }
/// <inheritdoc />
public HtmlString DisplayName(string expression) public HtmlString DisplayName(string expression)
{ {
var modelMetadata = string.IsNullOrEmpty(expression) ? var modelMetadata = string.IsNullOrEmpty(expression) ?
@ -245,6 +261,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
/// <inheritdoc />
public HtmlString DropDownList(string name, IEnumerable<SelectListItem> selectList, string optionLabel, public HtmlString DropDownList(string name, IEnumerable<SelectListItem> selectList, string optionLabel,
object htmlAttributes) object htmlAttributes)
{ {
@ -256,13 +273,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: htmlAttributes); htmlAttributes: htmlAttributes);
} }
/// <inheritdoc />
public HtmlString Hidden(string name, object value, object htmlAttributes) public HtmlString Hidden(string name, object value, object htmlAttributes)
{ {
return GenerateHidden(metadata: null, name: name, value: value, useViewData: (value == null), return GenerateHidden(metadata: null, name: name, value: value, useViewData: (value == null),
htmlAttributes: htmlAttributes); htmlAttributes: htmlAttributes);
} }
/// <inheritdoc />
public HtmlString Label(string expression, string labelText, object htmlAttributes) public HtmlString Label(string expression, string labelText, object htmlAttributes)
{ {
var modelMetadata = string.IsNullOrEmpty(expression)? var modelMetadata = string.IsNullOrEmpty(expression)?
@ -278,12 +296,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes); htmlAttributes);
} }
/// <inheritdoc />
public virtual HtmlString Name(string name) public virtual HtmlString Name(string name)
{ {
var fullName = ViewData.TemplateInfo.GetFullHtmlFieldName(name); var fullName = ViewData.TemplateInfo.GetFullHtmlFieldName(name);
return new HtmlString(Encode(fullName)); return new HtmlString(Encode(fullName));
} }
/// <inheritdoc />
public async Task<HtmlString> PartialAsync([NotNull] string partialViewName, object model, public async Task<HtmlString> PartialAsync([NotNull] string partialViewName, object model,
ViewDataDictionary viewData) ViewDataDictionary viewData)
{ {
@ -295,6 +315,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
/// <inheritdoc />
public Task RenderPartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData) public Task RenderPartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData)
{ {
return RenderPartialCoreAsync(partialViewName, model, viewData, ViewContext.Writer); return RenderPartialCoreAsync(partialViewName, model, viewData, ViewContext.Writer);
@ -351,27 +372,32 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
/// <inheritdoc />
public HtmlString Password(string name, object value, object htmlAttributes) public HtmlString Password(string name, object value, object htmlAttributes)
{ {
return GeneratePassword(metadata: null, name: name, value: value, htmlAttributes: htmlAttributes); return GeneratePassword(metadata: null, name: name, value: value, htmlAttributes: htmlAttributes);
} }
/// <inheritdoc />
public HtmlString RadioButton(string name, object value, bool? isChecked, object htmlAttributes) public HtmlString RadioButton(string name, object value, bool? isChecked, object htmlAttributes)
{ {
return GenerateRadioButton(metadata: null, name: name, value: value, isChecked: isChecked, return GenerateRadioButton(metadata: null, name: name, value: value, isChecked: isChecked,
htmlAttributes: htmlAttributes); htmlAttributes: htmlAttributes);
} }
/// <inheritdoc />
public HtmlString Raw(string value) public HtmlString Raw(string value)
{ {
return new HtmlString(value); return new HtmlString(value);
} }
/// <inheritdoc />
public HtmlString Raw(object value) public HtmlString Raw(object value)
{ {
return new HtmlString(value == null ? null : value.ToString()); return new HtmlString(value == null ? null : value.ToString());
} }
/// <inheritdoc />
public virtual HtmlString ValidationSummary(bool excludePropertyErrors, string message, IDictionary<string, object> htmlAttributes) public virtual HtmlString ValidationSummary(bool excludePropertyErrors, string message, IDictionary<string, object> htmlAttributes)
{ {
var formContext = ViewContext.ClientValidationEnabled ? ViewContext.FormContext : null; var formContext = ViewContext.ClientValidationEnabled ? ViewContext.FormContext : null;
@ -481,12 +507,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
/// <inheritdoc />
public HtmlString TextBox(string name, object value, string format, IDictionary<string, object> htmlAttributes) public HtmlString TextBox(string name, object value, string format, IDictionary<string, object> htmlAttributes)
{ {
return GenerateTextBox(metadata: null, name: name, value: value, format: format, return GenerateTextBox(metadata: null, name: name, value: value, format: format,
htmlAttributes: htmlAttributes); htmlAttributes: htmlAttributes);
} }
/// <inheritdoc />
public HtmlString Value([NotNull] string name, string format) public HtmlString Value([NotNull] string name, string format)
{ {
return GenerateValue(name, value: null, format: format, useViewData: true); return GenerateValue(name, value: null, format: format, useViewData: true);
@ -589,7 +617,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
format: null, format: null,
htmlAttributes: htmlAttributeDictionary); htmlAttributes: htmlAttributeDictionary);
} }
protected virtual HtmlString GenerateDisplayName([NotNull] ModelMetadata metadata, string htmlFieldName) protected virtual HtmlString GenerateDisplayName([NotNull] ModelMetadata metadata, string htmlFieldName)
{ {
// We don't call ModelMetadata.GetDisplayName here because // We don't call ModelMetadata.GetDisplayName here because
@ -603,7 +631,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
string.Empty : string.Empty :
htmlFieldName.Split('.').Last(); htmlFieldName.Split('.').Last();
} }
return new HtmlString(Encode(resolvedDisplayName)); return new HtmlString(Encode(resolvedDisplayName));
} }
@ -695,7 +723,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
format: null, format: null,
htmlAttributes: htmlAttributeDictionary); htmlAttributes: htmlAttributeDictionary);
} }
protected virtual HtmlString GenerateLabel([NotNull] ModelMetadata metadata, protected virtual HtmlString GenerateLabel([NotNull] ModelMetadata metadata,
string htmlFieldName, string htmlFieldName,
string labelText, string labelText,

View File

@ -91,7 +91,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
/// <inheritdoc /> /// <inheritdoc />
public HtmlString DisplayNameForInnerType<TInnerModel, TValue>(Expression<Func<TInnerModel, TValue>> expression) public HtmlString DisplayNameForInnerType<TInnerModel, TValue>(
[NotNull] Expression<Func<TInnerModel, TValue>> expression)
{ {
var metadata = ExpressionMetadataProvider. var metadata = ExpressionMetadataProvider.
FromLambdaExpression<TInnerModel, TValue>( FromLambdaExpression<TInnerModel, TValue>(
@ -175,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
/// <inheritdoc /> /// <inheritdoc />
public HtmlString ValueFor<TProperty>(Expression<Func<TModel, TProperty>> expression, string format) public HtmlString ValueFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression, string format)
{ {
var metadata = GetModelMetadata(expression); var metadata = GetModelMetadata(expression);
return GenerateValue(ExpressionHelper.GetExpressionText(expression), metadata.Model, format, return GenerateValue(ExpressionHelper.GetExpressionText(expression), metadata.Model, format,

View File

@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return string.Empty; return string.Empty;
} }
var viewData = new ViewDataDictionary<object>(_viewData) var viewData = new ViewDataDictionary(_viewData)
{ {
Model = _metadata.Model, Model = _metadata.Model,
ModelMetadata = _metadata ModelMetadata = _metadata

View File

@ -14,8 +14,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
private static readonly string DisplayTemplateViewPath = "DisplayTemplates"; private static readonly string DisplayTemplateViewPath = "DisplayTemplates";
private static readonly string EditorTemplateViewPath = "EditorTemplates"; private static readonly string EditorTemplateViewPath = "EditorTemplates";
private static readonly Dictionary<string, Func<IHtmlHelper<object>, string>> _defaultDisplayActions = private static readonly Dictionary<string, Func<IHtmlHelper, string>> _defaultDisplayActions =
new Dictionary<string, Func<IHtmlHelper<object>, string>>(StringComparer.OrdinalIgnoreCase) new Dictionary<string, Func<IHtmlHelper, string>>(StringComparer.OrdinalIgnoreCase)
{ {
{ "EmailAddress", DefaultDisplayTemplates.EmailAddressTemplate }, { "EmailAddress", DefaultDisplayTemplates.EmailAddressTemplate },
{ "HiddenInput", DefaultDisplayTemplates.HiddenInputTemplate }, { "HiddenInput", DefaultDisplayTemplates.HiddenInputTemplate },
@ -30,16 +30,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
}; };
private ViewContext _viewContext; private ViewContext _viewContext;
private ViewDataDictionary<object> _viewData; private ViewDataDictionary _viewData;
private IViewEngine _viewEngine; private IViewEngine _viewEngine;
private string _templateName; private string _templateName;
private bool _readOnly; private bool _readOnly;
public TemplateRenderer([NotNull] IViewEngine viewEngine, public TemplateRenderer(
[NotNull] ViewContext viewContext, [NotNull] IViewEngine viewEngine,
[NotNull] ViewDataDictionary<object> viewData, [NotNull] ViewContext viewContext,
string templateName, [NotNull] ViewDataDictionary viewData,
bool readOnly) string templateName,
bool readOnly)
{ {
_viewEngine = viewEngine; _viewEngine = viewEngine;
_viewContext = viewContext; _viewContext = viewContext;
@ -75,7 +76,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
Func<IHtmlHelper<object>, string> defaultAction; Func<IHtmlHelper, string> defaultAction;
if (defaultActions.TryGetValue(viewName, out defaultAction)) if (defaultActions.TryGetValue(viewName, out defaultAction))
{ {
return defaultAction(MakeHtmlHelper(_viewContext, _viewData)); return defaultAction(MakeHtmlHelper(_viewContext, _viewData));
@ -86,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
Resources.FormatTemplateHelpers_NoTemplate(_viewData.ModelMetadata.RealModelType.FullName)); Resources.FormatTemplateHelpers_NoTemplate(_viewData.ModelMetadata.RealModelType.FullName));
} }
private Dictionary<string, Func<IHtmlHelper<object>, string>> GetDefaultActions() private Dictionary<string, Func<IHtmlHelper, string>> GetDefaultActions()
{ {
if (_readOnly) if (_readOnly)
{ {
@ -170,9 +171,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
} }
} }
private static IHtmlHelper<object> MakeHtmlHelper(ViewContext viewContext, ViewDataDictionary<object> viewData) private static IHtmlHelper MakeHtmlHelper(ViewContext viewContext, ViewDataDictionary viewData)
{ {
var newHelper = viewContext.HttpContext.RequestServices.GetService<IHtmlHelper<object>>(); var newHelper = viewContext.HttpContext.RequestServices.GetService<IHtmlHelper>();
var contextable = newHelper as ICanHasViewContext; var contextable = newHelper as ICanHasViewContext;
if (contextable != null) if (contextable != null)

View File

@ -5,39 +5,42 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class HtmlHelperDisplayExtensions public static class HtmlHelperDisplayExtensions
{ {
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString Display([NotNull] this IHtmlHelper html, string expression)
string expression)
{ {
return html.Display(expression, templateName: null, htmlFieldName: null, additionalViewData: null); return html.Display(expression, templateName: null, htmlFieldName: null, additionalViewData: null);
} }
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString Display(
string expression, [NotNull] this IHtmlHelper html,
object additionalViewData) string expression,
object additionalViewData)
{ {
return html.Display(expression, templateName: null, htmlFieldName: null, return html.Display(expression, templateName: null, htmlFieldName: null,
additionalViewData: additionalViewData); additionalViewData: additionalViewData);
} }
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString Display(
string expression, [NotNull] this IHtmlHelper html,
string templateName) string expression,
string templateName)
{ {
return html.Display(expression, templateName, htmlFieldName: null, additionalViewData: null); return html.Display(expression, templateName, htmlFieldName: null, additionalViewData: null);
} }
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString Display(
string expression, [NotNull] this IHtmlHelper html,
string templateName, string expression,
object additionalViewData) string templateName,
object additionalViewData)
{ {
return html.Display(expression, templateName, htmlFieldName: null, additionalViewData: additionalViewData); return html.Display(expression, templateName, htmlFieldName: null, additionalViewData: additionalViewData);
} }
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString Display(
string expression, [NotNull] this IHtmlHelper html,
string templateName, string expression,
string htmlFieldName) string templateName,
string htmlFieldName)
{ {
return html.Display(expression, templateName, htmlFieldName, additionalViewData: null); return html.Display(expression, templateName, htmlFieldName, additionalViewData: null);
} }
@ -82,34 +85,34 @@ namespace Microsoft.AspNet.Mvc.Rendering
additionalViewData: null); additionalViewData: null);
} }
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html) public static HtmlString DisplayForModel([NotNull] this IHtmlHelper html)
{ {
return html.DisplayForModel(templateName: null, htmlFieldName: null, additionalViewData: null); return html.DisplayForModel(templateName: null, htmlFieldName: null, additionalViewData: null);
} }
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString DisplayForModel([NotNull] this IHtmlHelper html, object additionalViewData)
object additionalViewData)
{ {
return html.DisplayForModel(templateName: null, htmlFieldName: null, return html.DisplayForModel(templateName: null, htmlFieldName: null,
additionalViewData: additionalViewData); additionalViewData: additionalViewData);
} }
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString DisplayForModel([NotNull] this IHtmlHelper html, string templateName)
string templateName)
{ {
return html.DisplayForModel(templateName, htmlFieldName: null, additionalViewData: null); return html.DisplayForModel(templateName, htmlFieldName: null, additionalViewData: null);
} }
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString DisplayForModel(
string templateName, [NotNull] this IHtmlHelper html,
object additionalViewData) string templateName,
object additionalViewData)
{ {
return html.DisplayForModel(templateName, htmlFieldName: null, additionalViewData: additionalViewData); return html.DisplayForModel(templateName, htmlFieldName: null, additionalViewData: additionalViewData);
} }
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString DisplayForModel(
string templateName, [NotNull] this IHtmlHelper html,
string htmlFieldName) string templateName,
string htmlFieldName)
{ {
return html.DisplayForModel(templateName, htmlFieldName, additionalViewData: null); return html.DisplayForModel(templateName, htmlFieldName, additionalViewData: null);
} }

View File

@ -1,7 +1,7 @@
 using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq.Expressions; using System.Linq.Expressions;
namespace Microsoft.AspNet.Mvc.Rendering namespace Microsoft.AspNet.Mvc.Rendering
{ {
/// <summary> /// <summary>
@ -12,9 +12,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <summary> /// <summary>
/// Gets the display name for the current model. /// Gets the display name for the current model.
/// </summary> /// </summary>
/// <param name="htmlHelper">The <see cref="IHtmlHelper{T}"/> instance that this method extends.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns> /// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
public static HtmlString DisplayNameForModel<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper) public static HtmlString DisplayNameForModel([NotNull] this IHtmlHelper htmlHelper)
{ {
return htmlHelper.DisplayName(string.Empty); return htmlHelper.DisplayName(string.Empty);
} }
@ -27,8 +26,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns> /// <returns>
/// The display name for the model. /// The display name for the model.
/// </returns> /// </returns>
public static HtmlString DisplayNameFor<TInnerModel,TValue>(this IHtmlHelper<IEnumerable<TInnerModel>> htmlHelper, public static HtmlString DisplayNameFor<TInnerModel,TValue>(
Expression<Func<TInnerModel, TValue>> expression) [NotNull] this IHtmlHelper<IEnumerable<TInnerModel>> htmlHelper,
[NotNull] Expression<Func<TInnerModel, TValue>> expression)
{ {
return htmlHelper.DisplayNameForInnerType<TInnerModel, TValue>(expression); return htmlHelper.DisplayNameForInnerType<TInnerModel, TValue>(expression);
} }

View File

@ -3,62 +3,80 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class HtmlHelperFormExtensions public static class HtmlHelperFormExtensions
{ {
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper) public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper)
{ {
// Generates <form action="{current url}" method="post">. // Generates <form action="{current url}" method="post">.
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null, return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null,
method: FormMethod.Post, htmlAttributes: null); method: FormMethod.Post, htmlAttributes: null);
} }
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, FormMethod method) public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper, FormMethod method)
{ {
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null, return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null,
method: method, htmlAttributes: null); method: method, htmlAttributes: null);
} }
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, FormMethod method, public static MvcForm BeginForm(
object htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
FormMethod method,
object htmlAttributes)
{ {
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null, return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null,
method: method, htmlAttributes: htmlAttributes); method: method, htmlAttributes: htmlAttributes);
} }
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, object routeValues) public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper, object routeValues)
{ {
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: routeValues, return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: routeValues,
method: FormMethod.Post, htmlAttributes: null); method: FormMethod.Post, htmlAttributes: null);
} }
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string actionName, public static MvcForm BeginForm(
string controllerName) [NotNull] this IHtmlHelper htmlHelper,
string actionName,
string controllerName)
{ {
return htmlHelper.BeginForm(actionName, controllerName, routeValues: null, return htmlHelper.BeginForm(actionName, controllerName, routeValues: null,
method: FormMethod.Post, htmlAttributes: null); method: FormMethod.Post, htmlAttributes: null);
} }
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string actionName, public static MvcForm BeginForm(
string controllerName, object routeValues) [NotNull] this IHtmlHelper htmlHelper,
string actionName,
string controllerName,
object routeValues)
{ {
return htmlHelper.BeginForm(actionName, controllerName, routeValues, return htmlHelper.BeginForm(actionName, controllerName, routeValues,
FormMethod.Post, htmlAttributes: null); FormMethod.Post, htmlAttributes: null);
} }
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string actionName, public static MvcForm BeginForm(
string controllerName, FormMethod method) [NotNull] this IHtmlHelper htmlHelper,
string actionName,
string controllerName,
FormMethod method)
{ {
return htmlHelper.BeginForm(actionName, controllerName, routeValues: null, return htmlHelper.BeginForm(actionName, controllerName, routeValues: null,
method: method, htmlAttributes: null); method: method, htmlAttributes: null);
} }
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string actionName, public static MvcForm BeginForm(
string controllerName, object routeValues, FormMethod method) [NotNull] this IHtmlHelper htmlHelper,
string actionName,
string controllerName,
object routeValues,
FormMethod method)
{ {
return htmlHelper.BeginForm(actionName, controllerName, routeValues, return htmlHelper.BeginForm(actionName, controllerName, routeValues,
method, htmlAttributes: null); method, htmlAttributes: null);
} }
public static MvcForm BeginForm<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string actionName, public static MvcForm BeginForm(
string controllerName, FormMethod method, object htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
string actionName,
string controllerName,
FormMethod method,
object htmlAttributes)
{ {
return htmlHelper.BeginForm(actionName, controllerName, routeValues: null, return htmlHelper.BeginForm(actionName, controllerName, routeValues: null,
method: method, htmlAttributes: htmlAttributes); method: method, htmlAttributes: htmlAttributes);

View File

@ -6,18 +6,22 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class HtmlHelperInputExtensions public static class HtmlHelperInputExtensions
{ {
public static HtmlString CheckBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name) public static HtmlString CheckBox([NotNull] this IHtmlHelper htmlHelper, string name)
{ {
return htmlHelper.CheckBox(name, isChecked: null, htmlAttributes: null); return htmlHelper.CheckBox(name, isChecked: null, htmlAttributes: null);
} }
public static HtmlString CheckBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString CheckBox(
[NotNull] this IHtmlHelper htmlHelper,
string name,
bool isChecked) bool isChecked)
{ {
return htmlHelper.CheckBox(name, isChecked, htmlAttributes: null); return htmlHelper.CheckBox(name, isChecked, htmlAttributes: null);
} }
public static HtmlString CheckBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString CheckBox(
[NotNull] this IHtmlHelper htmlHelper,
string name,
object htmlAttributes) object htmlAttributes)
{ {
return htmlHelper.CheckBox(name, isChecked: null, htmlAttributes: htmlAttributes); return htmlHelper.CheckBox(name, isChecked: null, htmlAttributes: htmlAttributes);
@ -29,12 +33,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
return htmlHelper.CheckBoxFor(expression, htmlAttributes: null); return htmlHelper.CheckBoxFor(expression, htmlAttributes: null);
} }
public static HtmlString Hidden<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name) public static HtmlString Hidden([NotNull] this IHtmlHelper htmlHelper, string name)
{ {
return htmlHelper.Hidden(name, value: null, htmlAttributes: null); return htmlHelper.Hidden(name, value: null, htmlAttributes: null);
} }
public static HtmlString Hidden<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString Hidden(
[NotNull] this IHtmlHelper htmlHelper,
string name,
object value) object value)
{ {
return htmlHelper.Hidden(name, value, htmlAttributes: null); return htmlHelper.Hidden(name, value, htmlAttributes: null);
@ -46,12 +52,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
return htmlHelper.HiddenFor(expression, htmlAttributes: null); return htmlHelper.HiddenFor(expression, htmlAttributes: null);
} }
public static HtmlString Password<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name) public static HtmlString Password([NotNull] this IHtmlHelper htmlHelper, string name)
{ {
return htmlHelper.Password(name, value: null, htmlAttributes: null); return htmlHelper.Password(name, value: null, htmlAttributes: null);
} }
public static HtmlString Password<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString Password(
[NotNull] this IHtmlHelper htmlHelper,
string name,
object value) object value)
{ {
return htmlHelper.Password(name, value, htmlAttributes: null); return htmlHelper.Password(name, value, htmlAttributes: null);
@ -63,20 +71,28 @@ namespace Microsoft.AspNet.Mvc.Rendering
return htmlHelper.PasswordFor(expression, htmlAttributes: null); return htmlHelper.PasswordFor(expression, htmlAttributes: null);
} }
public static HtmlString RadioButton<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString RadioButton(
[NotNull] this IHtmlHelper htmlHelper,
string name,
object value) object value)
{ {
return htmlHelper.RadioButton(name, value, isChecked: null, htmlAttributes: null); return htmlHelper.RadioButton(name, value, isChecked: null, htmlAttributes: null);
} }
public static HtmlString RadioButton<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString RadioButton(
object value, object htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
string name,
object value,
object htmlAttributes)
{ {
return htmlHelper.RadioButton(name, value, isChecked: null, htmlAttributes: htmlAttributes); return htmlHelper.RadioButton(name, value, isChecked: null, htmlAttributes: htmlAttributes);
} }
public static HtmlString RadioButton<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString RadioButton(
object value, bool isChecked) [NotNull] this IHtmlHelper htmlHelper,
string name,
object value,
bool isChecked)
{ {
return htmlHelper.RadioButton(name, value, isChecked, htmlAttributes: null); return htmlHelper.RadioButton(name, value, isChecked, htmlAttributes: null);
} }
@ -87,38 +103,53 @@ namespace Microsoft.AspNet.Mvc.Rendering
return htmlHelper.RadioButtonFor(expression, value, htmlAttributes: null); return htmlHelper.RadioButtonFor(expression, value, htmlAttributes: null);
} }
public static HtmlString TextBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name) public static HtmlString TextBox([NotNull] this IHtmlHelper htmlHelper, string name)
{ {
return TextBox(htmlHelper, name, value: null); return TextBox(htmlHelper, name, value: null);
} }
public static HtmlString TextBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString TextBox(
[NotNull] this IHtmlHelper htmlHelper,
string name,
object value) object value)
{ {
return TextBox(htmlHelper, name, value, format: null); return TextBox(htmlHelper, name, value, format: null);
} }
public static HtmlString TextBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString TextBox(
object value, string format) [NotNull] this IHtmlHelper htmlHelper,
string name,
object value,
string format)
{ {
return TextBox(htmlHelper, name, value, format, htmlAttributes: null); return TextBox(htmlHelper, name, value, format, htmlAttributes: null);
} }
public static HtmlString TextBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString TextBox(
object value, object htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
string name,
object value,
object htmlAttributes)
{ {
return TextBox(htmlHelper, name, value, format: null, htmlAttributes: htmlAttributes); return TextBox(htmlHelper, name, value, format: null, htmlAttributes: htmlAttributes);
} }
public static HtmlString TextBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString TextBox(
object value, string format, object htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
string name,
object value,
string format,
object htmlAttributes)
{ {
return htmlHelper.TextBox(name, value, format, return htmlHelper.TextBox(name, value, format,
HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
} }
public static HtmlString TextBox<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString TextBox(
object value, IDictionary<string, object> htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
string name,
object value,
IDictionary<string, object> htmlAttributes)
{ {
return htmlHelper.TextBox(name, value, format: null, htmlAttributes: htmlAttributes); return htmlHelper.TextBox(name, value, format: null, htmlAttributes: htmlAttributes);
} }

View File

@ -5,16 +5,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class HtmlHelperLabelExtensions public static class HtmlHelperLabelExtensions
{ {
public static HtmlString Label<TModel>([NotNull] this IHtmlHelper<TModel> html, string expression) public static HtmlString Label([NotNull] this IHtmlHelper html, string expression)
{ {
return html.Label(expression, return html.Label(expression,
labelText: null, labelText: null,
htmlAttributes: null); htmlAttributes: null);
} }
public static HtmlString Label<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString Label([NotNull] this IHtmlHelper html, string expression, string labelText)
string expression,
string labelText)
{ {
return html.Label(expression, labelText, htmlAttributes: null); return html.Label(expression, labelText, htmlAttributes: null);
} }
@ -39,25 +37,25 @@ namespace Microsoft.AspNet.Mvc.Rendering
return html.LabelFor<TValue>(expression, labelText: null, htmlAttributes: htmlAttributes); return html.LabelFor<TValue>(expression, labelText: null, htmlAttributes: htmlAttributes);
} }
public static HtmlString LabelForModel<TModel>([NotNull] this IHtmlHelper<TModel> html) public static HtmlString LabelForModel([NotNull] this IHtmlHelper html)
{ {
return LabelForModel(html, labelText: null); return LabelForModel(html, labelText: null);
} }
public static HtmlString LabelForModel<TModel>([NotNull] this IHtmlHelper<TModel> html, string labelText) public static HtmlString LabelForModel([NotNull] this IHtmlHelper html, string labelText)
{ {
return html.Label(expression: string.Empty, labelText: labelText, htmlAttributes: null); return html.Label(expression: string.Empty, labelText: labelText, htmlAttributes: null);
} }
public static HtmlString LabelForModel<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString LabelForModel([NotNull] this IHtmlHelper html, object htmlAttributes)
object htmlAttributes)
{ {
return html.Label(expression: string.Empty, labelText: null, htmlAttributes: htmlAttributes); return html.Label(expression: string.Empty, labelText: null, htmlAttributes: htmlAttributes);
} }
public static HtmlString LabelForModel<TModel>([NotNull] this IHtmlHelper<TModel> html, public static HtmlString LabelForModel(
string labelText, [NotNull] this IHtmlHelper html,
object htmlAttributes) string labelText,
object htmlAttributes)
{ {
return html.Label(expression: string.Empty, labelText: labelText, htmlAttributes: htmlAttributes); return html.Label(expression: string.Empty, labelText: labelText, htmlAttributes: htmlAttributes);
} }

View File

@ -3,9 +3,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class HtmlHelperLinkExtensions public static class HtmlHelperLinkExtensions
{ {
public static HtmlString ActionLink<TModel>( public static HtmlString ActionLink(
[NotNull] this IHtmlHelper<TModel> helper, [NotNull] this IHtmlHelper helper,
[NotNull] string linkText, [NotNull] string linkText,
string actionName) string actionName)
{ {
return helper.ActionLink( return helper.ActionLink(
@ -19,10 +19,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null); htmlAttributes: null);
} }
public static HtmlString ActionLink<TModel>( public static HtmlString ActionLink(
[NotNull] this IHtmlHelper<TModel> helper, [NotNull] this IHtmlHelper helper,
[NotNull] string linkText, [NotNull] string linkText,
string actionName, string actionName,
object routeValues) object routeValues)
{ {
return helper.ActionLink( return helper.ActionLink(
@ -36,11 +36,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null); htmlAttributes: null);
} }
public static HtmlString ActionLink<TModel>( public static HtmlString ActionLink(
[NotNull] this IHtmlHelper<TModel> helper, [NotNull] this IHtmlHelper helper,
[NotNull] string linkText, [NotNull] string linkText,
string actionName, string actionName,
object routeValues, object routeValues,
object htmlAttributes) object htmlAttributes)
{ {
return helper.ActionLink( return helper.ActionLink(
@ -54,10 +54,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: htmlAttributes); htmlAttributes: htmlAttributes);
} }
public static HtmlString ActionLink<TModel>( public static HtmlString ActionLink(
[NotNull] this IHtmlHelper<TModel> helper, [NotNull] this IHtmlHelper helper,
[NotNull] string linkText, [NotNull] string linkText,
string actionName, string actionName,
string controllerName) string controllerName)
{ {
return helper.ActionLink( return helper.ActionLink(
@ -71,8 +71,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null); htmlAttributes: null);
} }
public static HtmlString ActionLink<TModel>( public static HtmlString ActionLink(
[NotNull] this IHtmlHelper<TModel> helper, [NotNull] this IHtmlHelper helper,
[NotNull] string linkText, [NotNull] string linkText,
string actionName, string actionName,
string controllerName, string controllerName,
@ -89,12 +89,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null); htmlAttributes: null);
} }
public static HtmlString ActionLink<TModel>( public static HtmlString ActionLink(
[NotNull] this IHtmlHelper<TModel> helper, [NotNull] this IHtmlHelper helper,
[NotNull] string linkText, [NotNull] string linkText,
string actionName, string actionName,
string controllerName, string controllerName,
object routeValues, object routeValues,
object htmlAttributes) object htmlAttributes)
{ {
return helper.ActionLink( return helper.ActionLink(

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </summary> /// </summary>
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param> /// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns> /// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
public static HtmlString NameForModel<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper) public static HtmlString NameForModel([NotNull] this IHtmlHelper htmlHelper)
{ {
return htmlHelper.Name(string.Empty); return htmlHelper.Name(string.Empty);
} }

View File

@ -7,13 +7,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <summary> /// <summary>
/// Renders the partial view with the parent's view data and model to a string. /// Renders the partial view with the parent's view data and model to a string.
/// </summary> /// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param> /// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
/// <param name="partialViewName">The name of the partial view to render.</param> /// <param name="partialViewName">The name of the partial view to render.</param>
/// <returns> /// <returns>
/// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed. /// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.
/// </returns> /// </returns>
public static Task<HtmlString> PartialAsync<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static Task<HtmlString> PartialAsync(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName) [NotNull] string partialViewName)
{ {
return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null); return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null);
@ -22,7 +22,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <summary> /// <summary>
/// Renders the partial view with the given view data and, implicitly, the given view data's model to a string. /// Renders the partial view with the given view data and, implicitly, the given view data's model to a string.
/// </summary> /// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param> /// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
/// <param name="partialViewName">The name of the partial view to render.</param> /// <param name="partialViewName">The name of the partial view to render.</param>
/// <param name="viewData"> /// <param name="viewData">
@ -31,8 +30,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns> /// <returns>
/// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed. /// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.
/// </returns> /// </returns>
public static Task<HtmlString> PartialAsync<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static Task<HtmlString> PartialAsync(
[NotNull] string partialViewName, ViewDataDictionary viewData) [NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
ViewDataDictionary viewData)
{ {
return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData); return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData);
} }
@ -40,15 +41,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <summary> /// <summary>
/// Renders the partial view with an empty view data and the given model to a string. /// Renders the partial view with an empty view data and the given model to a string.
/// </summary> /// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param> /// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
/// <param name="partialViewName">The name of the partial view to render.</param> /// <param name="partialViewName">The name of the partial view to render.</param>
/// <param name="model">The model to provide to the partial view that will be rendered.</param> /// <param name="model">The model to provide to the partial view that will be rendered.</param>
/// <returns> /// <returns>
/// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed. /// A <see cref="Task{T}"/> that represents when rendering to the <see cref="HtmlString"/> has completed.
/// </returns> /// </returns>
public static Task<HtmlString> PartialAsync<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static Task<HtmlString> PartialAsync(
[NotNull] string partialViewName, object model) [NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
object model)
{ {
return htmlHelper.PartialAsync(partialViewName, model, viewData: null); return htmlHelper.PartialAsync(partialViewName, model, viewData: null);
} }
@ -56,11 +58,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <summary> /// <summary>
/// Renders the partial view with the parent's view data and model. /// Renders the partial view with the parent's view data and model.
/// </summary> /// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param> /// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
/// <param name="partialViewName">The name of the partial view to render.</param> /// <param name="partialViewName">The name of the partial view to render.</param>
/// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns> /// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns>
public static Task RenderPartialAsync<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static Task RenderPartialAsync(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName) [NotNull] string partialViewName)
{ {
return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model,
@ -70,15 +72,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <summary> /// <summary>
/// Renders the partial view with the given view data and, implicitly, the given view data's model. /// Renders the partial view with the given view data and, implicitly, the given view data's model.
/// </summary> /// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param> /// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
/// <param name="partialViewName">The name of the partial view to render.</param> /// <param name="partialViewName">The name of the partial view to render.</param>
/// <param name="viewData"> /// <param name="viewData">
/// The <see cref="ViewDataDictionary"/> that is provided to the partial view that will be rendered. /// The <see cref="ViewDataDictionary"/> that is provided to the partial view that will be rendered.
/// </param> /// </param>
/// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns> /// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns>
public static Task RenderPartialAsync<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static Task RenderPartialAsync(
[NotNull] string partialViewName, ViewDataDictionary viewData) [NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
ViewDataDictionary viewData)
{ {
return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData); return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData);
} }
@ -86,13 +89,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <summary> /// <summary>
/// Renders the partial view with an empty view data and the given model. /// Renders the partial view with an empty view data and the given model.
/// </summary> /// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the model.</typeparam>
/// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param> /// <param name="htmlHelper">The <see cref="HtmlHelper"/> instance that this method extends.</param>
/// <param name="partialViewName">The name of the partial view to render.</param> /// <param name="partialViewName">The name of the partial view to render.</param>
/// <param name="model">The model to provide to the partial view that will be rendered.</param> /// <param name="model">The model to provide to the partial view that will be rendered.</param>
/// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns> /// <returns>A <see cref="Task"/> that represents when rendering has completed.</returns>
public static Task RenderPartialAsync<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static Task RenderPartialAsync(
[NotNull] string partialViewName, object model) [NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
object model)
{ {
return htmlHelper.RenderPartialAsync(partialViewName, model, htmlHelper.ViewData); return htmlHelper.RenderPartialAsync(partialViewName, model, htmlHelper.ViewData);
} }

View File

@ -6,31 +6,38 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class SelectExtensions public static class SelectExtensions
{ {
public static HtmlString DropDownList<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name) public static HtmlString DropDownList([NotNull] this IHtmlHelper htmlHelper, string name)
{ {
return htmlHelper.DropDownList(name, selectList: null, optionLabel: null, htmlAttributes: null); return htmlHelper.DropDownList(name, selectList: null, optionLabel: null, htmlAttributes: null);
} }
public static HtmlString DropDownList<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString DropDownList([NotNull] this IHtmlHelper htmlHelper, string name, string optionLabel)
string optionLabel)
{ {
return htmlHelper.DropDownList(name, selectList: null, optionLabel: optionLabel, htmlAttributes: null); return htmlHelper.DropDownList(name, selectList: null, optionLabel: optionLabel, htmlAttributes: null);
} }
public static HtmlString DropDownList<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
string name,
IEnumerable<SelectListItem> selectList) IEnumerable<SelectListItem> selectList)
{ {
return htmlHelper.DropDownList(name, selectList, optionLabel: null, htmlAttributes: null); return htmlHelper.DropDownList(name, selectList, optionLabel: null, htmlAttributes: null);
} }
public static HtmlString DropDownList<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString DropDownList(
IEnumerable<SelectListItem> selectList, object htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
string name,
IEnumerable<SelectListItem> selectList,
object htmlAttributes)
{ {
return htmlHelper.DropDownList(name, selectList, optionLabel: null, htmlAttributes: htmlAttributes); return htmlHelper.DropDownList(name, selectList, optionLabel: null, htmlAttributes: htmlAttributes);
} }
public static HtmlString DropDownList<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name, public static HtmlString DropDownList(
IEnumerable<SelectListItem> selectList, string optionLabel) [NotNull] this IHtmlHelper htmlHelper,
string name,
IEnumerable<SelectListItem> selectList,
string optionLabel)
{ {
return htmlHelper.DropDownList(name, selectList, optionLabel, htmlAttributes: null); return htmlHelper.DropDownList(name, selectList, optionLabel, htmlAttributes: null);
} }

View File

@ -4,46 +4,53 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class HtmlHelperValidationExtensions public static class HtmlHelperValidationExtensions
{ {
public static HtmlString ValidationSummary<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper) public static HtmlString ValidationSummary([NotNull] this IHtmlHelper htmlHelper)
{ {
return ValidationSummary(htmlHelper, excludePropertyErrors: false); return ValidationSummary(htmlHelper, excludePropertyErrors: false);
} }
public static HtmlString ValidationSummary<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static HtmlString ValidationSummary([NotNull] this IHtmlHelper htmlHelper, bool excludePropertyErrors)
bool excludePropertyErrors)
{ {
return ValidationSummary(htmlHelper, excludePropertyErrors, message: null); return ValidationSummary(htmlHelper, excludePropertyErrors, message: null);
} }
public static HtmlString ValidationSummary<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static HtmlString ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message)
string message)
{ {
return ValidationSummary(htmlHelper, excludePropertyErrors: false, message: message, return ValidationSummary(htmlHelper, excludePropertyErrors: false, message: message,
htmlAttributes: (object)null); htmlAttributes: (object)null);
} }
public static HtmlString ValidationSummary<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static HtmlString ValidationSummary(
bool excludePropertyErrors, string message) [NotNull] this IHtmlHelper htmlHelper,
bool excludePropertyErrors,
string message)
{ {
return ValidationSummary(htmlHelper, excludePropertyErrors, message, htmlAttributes: (object)null); return ValidationSummary(htmlHelper, excludePropertyErrors, message, htmlAttributes: (object)null);
} }
public static HtmlString ValidationSummary<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static HtmlString ValidationSummary(
string message, object htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
string message,
object htmlAttributes)
{ {
return ValidationSummary(htmlHelper, excludePropertyErrors: false, message: message, return ValidationSummary(htmlHelper, excludePropertyErrors: false, message: message,
htmlAttributes: HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); htmlAttributes: HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
} }
public static HtmlString ValidationSummary<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static HtmlString ValidationSummary(
bool excludePropertyErrors, string message, object htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
bool excludePropertyErrors,
string message,
object htmlAttributes)
{ {
return htmlHelper.ValidationSummary(excludePropertyErrors, message, return htmlHelper.ValidationSummary(excludePropertyErrors, message,
HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
} }
public static HtmlString ValidationSummary<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, public static HtmlString ValidationSummary(
string message, IDictionary<string, object> htmlAttributes) [NotNull] this IHtmlHelper htmlHelper,
string message,
IDictionary<string, object> htmlAttributes)
{ {
return htmlHelper.ValidationSummary(excludePropertyErrors: false, message: message, return htmlHelper.ValidationSummary(excludePropertyErrors: false, message: message,
htmlAttributes: htmlAttributes); htmlAttributes: htmlAttributes);

View File

@ -5,22 +5,24 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
public static class HtmlHelperValueExtensions public static class HtmlHelperValueExtensions
{ {
public static HtmlString Value<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string name) public static HtmlString Value([NotNull] this IHtmlHelper htmlHelper, string name)
{ {
return htmlHelper.Value(name, format: null); return htmlHelper.Value(name, format: null);
} }
public static HtmlString ValueFor<TModel, TProperty>([NotNull] this IHtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression) public static HtmlString ValueFor<TModel, TProperty>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TProperty>> expression)
{ {
return htmlHelper.ValueFor(expression, format: null); return htmlHelper.ValueFor(expression, format: null);
} }
public static HtmlString ValueForModel<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper) public static HtmlString ValueForModel([NotNull] this IHtmlHelper htmlHelper)
{ {
return ValueForModel<TModel>(htmlHelper, format: null); return ValueForModel(htmlHelper, format: null);
} }
public static HtmlString ValueForModel<TModel>([NotNull] this IHtmlHelper<TModel> htmlHelper, string format) public static HtmlString ValueForModel([NotNull] this IHtmlHelper htmlHelper, string format)
{ {
return htmlHelper.Value(string.Empty, format); return htmlHelper.Value(string.Empty, format);
} }

View File

@ -0,0 +1,358 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc.Rendering
{
/// <summary>
/// Base HTML helpers.
/// </summary>
public interface IHtmlHelper
{
/// <summary>
/// Gets or sets the character that replaces periods in the ID attribute of an element.
/// </summary>
string IdAttributeDotReplacement { get; set; }
/// <summary>
/// Gets the view bag.
/// </summary>
dynamic ViewBag { get; }
/// <summary>
/// Gets the context information about the view.
/// </summary>
ViewContext ViewContext { get; }
/// <summary>
/// Gets the current view data.
/// </summary>
ViewDataDictionary ViewData { get; }
/// <summary>
/// Returns an anchor element (a element) that contains a URL path to the specified action.
/// </summary>
/// <param name="linkText">The inner text of the anchor element.</param>
/// <param name="actionName">The name of the action.</param>
/// <param name="controllerName">The name of the controller.</param>
/// <param name="protocol">The protocol for the URL, such as &quot;http&quot; or &quot;https&quot;.</param>
/// <param name="hostname">The host name for the URL.</param>
/// <param name="fragment">The URL fragment name (the anchor name).</param>
/// <param name="routeValues">
/// An object that contains the parameters for a route. The parameters are retrieved through reflection by
/// examining the properties of the object. This object is typically created using object initializer syntax.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the route parameters.
/// </param>
/// <param name="htmlAttributes">
/// An object that contains the HTML attributes to set for the element. Alternatively, an
/// <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>
/// An anchor element (a element).
/// </returns>
HtmlString ActionLink(
[NotNull] string linkText,
string actionName,
string controllerName,
string protocol,
string hostname,
string fragment,
object routeValues,
object htmlAttributes);
/// <summary>
/// Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.
/// </summary>
/// <returns>
/// The generated form field (anti-forgery token).
/// </returns>
HtmlString AntiForgeryToken();
/// <summary>
/// Writes an opening <form> tag to the response. When the user submits the form,
/// the request will be processed by an action method.
/// </summary>
/// <param name="actionName">The name of the action method.</param>
/// <param name="controllerName">The name of the controller.</param>
/// <param name="routeValues">An object that contains the parameters for a route. The parameters are retrieved
/// through reflection by examining the properties of the object. This object is typically created using object
/// initializer syntax. Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the
/// route parameters.</param>
/// <param name="method">The HTTP method for processing the form, either GET or POST.</param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>An <see cref="MvcForm"/> instance which emits the closing {form} tag when disposed.</returns>
MvcForm BeginForm(
string actionName,
string controllerName,
object routeValues,
FormMethod method,
object htmlAttributes);
/// <summary>
/// Render an input element of type "checkbox" with value "true" and an input element of type "hidden" with
/// value "false".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="isChecked">
/// If <c>true</c>, checkbox is initially checked. Ignore if named value is found in submitted data. Finally
/// fall back to an existing "checked" value in <paramref name="htmlAttributes"/>.
/// </param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString CheckBox(string name, bool? isChecked, object htmlAttributes);
/// <summary>
/// Returns HTML markup for each property in the object that is represented by the expression, using the
/// specified template, HTML field ID, and additional view data.
/// </summary>
/// <param name="expression">An expression that identifies the object that contains the properties to display.
/// </param>
/// <param name="templateName">The name of the template that is used to render the object.</param>
/// <param name="htmlFieldName">
/// A string that is used to disambiguate the names of HTML input elements that are rendered for properties
/// that have the same name.
/// </param>
/// <param name="additionalViewData">
/// An anonymous object or dictionary that can contain additional view data that will be merged into the
/// <see cref="ViewDataDictionary{TModel}"/> instance that is created for the template.
/// </param>
/// <returns>The HTML markup for each property in the object that is represented by the expression.</returns>
HtmlString Display(
string expression,
string templateName,
string htmlFieldName,
object additionalViewData);
/// <summary>
/// Returns HTML markup for each property in the model, using the specified template, an HTML field ID, and
/// additional view data.
/// </summary>
/// <param name="templateName">The name of the template that is used to render the object.</param>
/// <param name="htmlFieldName">
/// A string that is used to disambiguate the names of HTML input elements that are rendered for properties
/// that have the same name.
/// </param>
/// <param name="additionalViewData">
/// An anonymous object or dictionary that can contain additional view data that will be merged into the
/// <see cref="ViewDataDictionary{TModel}"/> instance that is created for the template.
/// </param>
/// <returns>The HTML markup for each property in the model.</returns>
HtmlString DisplayForModel(string templateName, string htmlFieldName, object additionalViewData);
/// <summary>
/// Gets the display name.
/// </summary>
/// <param name="expression">An expression that identifies the object that contains the display name.</param>
/// <returns>
/// The display name.
/// </returns>
HtmlString DisplayName(string expression);
/// <summary>
/// Returns a single-selection HTML {select} element using the specified name of the form field,
/// list items, option label, and HTML attributes.
/// </summary>
/// <param name="name">The name of the form field to return.</param>
/// <param name="selectList">A collection of <see href="SelectListItem"/> objects that are used to populate the
/// drop-down list.</param>
/// <param name="optionLabel">The text for a default empty item. This parameter can be null.</param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the {select} element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>An HTML {select} element with an {option} subelement for each item in the list.</returns>
HtmlString DropDownList(
string name,
IEnumerable<SelectListItem> selectList,
string optionLabel,
object htmlAttributes);
/// <summary>
/// Converts the value of the specified object to an HTML-encoded string.
/// </summary>
/// <param name="value">The object to encode.</param>
/// <returns>The HTML-encoded string.</returns>
string Encode(object value);
/// <summary>
/// Converts the specified string to an HTML-encoded string.
/// </summary>
/// <param name="value">The string to encode.</param>
/// <returns>The HTML-encoded string.</returns>
string Encode(string value);
/// <summary>
/// Renders the closing </form> tag to the response.
/// </summary>
void EndForm();
/// <summary>
/// Formats the value.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="format">The format string.</param>
/// <returns>The formatted value.</returns>
string FormatValue(object value, string format);
/// <summary>
/// Creates an HTML element ID using the specified element name.
/// </summary>
/// <param name="name">The name of the HTML element.</param>
/// <returns>The ID of the HTML element.</returns>
string GenerateIdFromName(string name);
/// <summary>
/// Render an input element of type "hidden".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="value">
/// If non-<c>null</c>, value to include in the element. Ignore if named value is found in submitted data.
/// </param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString Hidden(string name, object value, object htmlAttributes);
/// <summary>
/// Returns an HTML label element and the property name of the property that is represented by the specified
/// expression.
/// </summary>
/// <param name="expression">An expression that identifies the property to display.</param>
/// <param name="labelText">The label text.</param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
/// <returns>
/// An HTML label element and the property name of the property that is represented by the expression.
/// </returns>
HtmlString Label(string expression, string labelText, object htmlAttributes);
/// <summary>
/// Gets the full HTML field name for the given expression <paramref name="name"/>.
/// </summary>
/// <param name="name">Name of an expression, relative to the current model.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString Name(string name);
/// <summary>
/// Returns a partial view in string format.
/// </summary>
/// <param name="partialViewName">The name of the partial view to render and return.</param>
/// <param name="model">A model to pass into the partial view.</param>
/// <param name="viewData">A <see cref="ViewDataDictionary"/> to pass into the partial view.</param>
/// <returns>A task that represents when rendering of the partial view into a string has completed.</returns>
Task<HtmlString> PartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData);
/// <summary>
/// Render an input element of type "password".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="value">
/// If non-<c>null</c>, value to include in the element.
/// </param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString Password(string name, object value, object htmlAttributes);
/// <summary>
/// Render an input element of type "radio".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="value">
/// If non-<c>null</c>, value to include in the element. May be <c>null</c> only if
/// <paramref name="isChecked"/> is also <c>null</c>. Also compared to value in submitted data or view data to
/// determine <paramref name="isChecked"/> if that parameter is <c>null</c>. Ignore if named value is found in
/// submitted data.
/// </param>
/// <param name="isChecked">
/// If <c>true</c>, radio button is initially selected. Ignore if named value is found in submitted data. Fall
/// back to comparing <paramref name="value"/> with view data if this parameter is <c>null</c>. Finally
/// fall back to an existing "checked" value in <paramref name="htmlAttributes"/>.
/// </param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString RadioButton(string name, object value, bool? isChecked, object htmlAttributes);
/// <summary>
/// Wraps HTML markup in an <see cref="HtmlString"/>, which will enable HTML markup to be
/// rendered to the output without getting HTML encoded.
/// </summary>
/// <param name="value">HTML markup string.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString Raw(string value);
/// <summary>
/// Wraps HTML markup from the string representation of an object in an <see cref="HtmlString"/>,
/// which will enable HTML markup to be rendered to the output without getting HTML encoded.
/// </summary>
/// <param name="value">object with string representation as HTML markup.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString Raw(object value);
/// <summary>
/// Renders a partial view.
/// </summary>
/// <param name="partialViewName">The name of the partial view to render.</param>
/// <param name="model">A model to pass into the partial view.</param>
/// <param name="viewData">A <see cref="ViewDataDictionary"/> to pass into the partial view.</param>
/// <returns>A task that represents when rendering has completed.</returns>
Task RenderPartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData);
/// <summary>
/// Render an input element of type "text".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="value">
/// If non-<c>null</c>, value to include in the element. Ignore if named value is found in submitted data.
/// </param>
/// <param name="format"></param>
/// <param name="htmlAttributes">
/// <see cref="IDictionary{string, object}"/> containing additional HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString TextBox(string name, object value, string format, IDictionary<string, object> htmlAttributes);
/// <summary>
/// Returns an unordered list (ul element) of validation messages that are in the
/// <see cref="ModelStateDictionary"/> object.
/// </summary>
/// <param name="excludePropertyErrors">true to have the summary display model-level errors only, or false to
/// have the summary display all errors.</param>
/// <param name="message">The message to display with the validation summary.</param>
/// <param name="htmlAttributes">A dictionary that contains the HTML attributes for the element.</param>
/// <returns>An <see cref="HtmlString"/> that contains an unordered list (ul element) of validation messages.
/// </returns>
HtmlString ValidationSummary(
bool excludePropertyErrors,
string message,
IDictionary<string, object> htmlAttributes);
/// <summary>
/// Returns the model value for the given expression <paramref name="name"/>.
/// </summary>
/// <param name="name">Name of an expression, relative to the current model.</param>
/// <param name="format">The optional format string to apply to the value.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString Value([NotNull] string name, string format);
}
}

View File

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Mvc.Rendering namespace Microsoft.AspNet.Mvc.Rendering
{ {
@ -9,107 +8,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An <see cref="IHtmlHelper"/> for Linq expressions. /// An <see cref="IHtmlHelper"/> for Linq expressions.
/// </summary> /// </summary>
/// <typeparam name="TModel">The <see cref="Type"/> of the model.</typeparam> /// <typeparam name="TModel">The <see cref="Type"/> of the model.</typeparam>
public interface IHtmlHelper<TModel> public interface IHtmlHelper<TModel> : IHtmlHelper
{ {
/// <summary>
/// Gets or sets the character that replaces periods in the ID attribute of an element.
/// </summary>
string IdAttributeDotReplacement { get; set; }
/// <summary>
/// Gets the view bag.
/// </summary>
dynamic ViewBag { get; }
/// <summary>
/// Gets the context information about the view.
/// </summary>
ViewContext ViewContext { get; }
/// <summary> /// <summary>
/// Gets the current view data. /// Gets the current view data.
/// </summary> /// </summary>
ViewDataDictionary<TModel> ViewData { get; } new ViewDataDictionary<TModel> ViewData { get; }
/// <summary>
/// Returns an anchor element (a element) that contains a URL path to the specified action.
/// </summary>
/// <param name="linkText">The inner text of the anchor element.</param>
/// <param name="actionName">The name of the action.</param>
/// <param name="controllerName">The name of the controller.</param>
/// <param name="protocol">The protocol for the URL, such as &quot;http&quot; or &quot;https&quot;.</param>
/// <param name="hostname">The host name for the URL.</param>
/// <param name="fragment">The URL fragment name (the anchor name).</param>
/// <param name="routeValues">
/// An object that contains the parameters for a route. The parameters are retrieved through reflection by
/// examining the properties of the object. This object is typically created using object initializer syntax.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the route parameters.
/// </param>
/// <param name="htmlAttributes">
/// An object that contains the HTML attributes to set for the element. Alternatively, an
/// <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>
/// An anchor element (a element).
/// </returns>
HtmlString ActionLink(
[NotNull] string linkText,
string actionName,
string controllerName,
string protocol,
string hostname,
string fragment,
object routeValues,
object htmlAttributes);
/// <summary>
/// Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.
/// </summary>
/// <returns>
/// The generated form field (anti-forgery token).
/// </returns>
HtmlString AntiForgeryToken();
/// <summary>
/// Writes an opening <form> tag to the response. When the user submits the form,
/// the request will be processed by an action method.
/// </summary>
/// <param name="actionName">The name of the action method.</param>
/// <param name="controllerName">The name of the controller.</param>
/// <param name="routeValues">An object that contains the parameters for a route. The parameters are retrieved
/// through reflection by examining the properties of the object. This object is typically created using object
/// initializer syntax. Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the
/// route parameters.</param>
/// <param name="method">The HTTP method for processing the form, either GET or POST.</param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>An <see cref="MvcForm"/> instance which emits the closing {form} tag when disposed.</returns>
MvcForm BeginForm(string actionName, string controllerName, object routeValues, FormMethod method,
object htmlAttributes);
/// <summary>
/// Renders the closing </form> tag to the response.
/// </summary>
void EndForm();
/// <summary>
/// Render an input element of type "checkbox" with value "true" and an input element of type "hidden" with
/// value "false".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="isChecked">
/// If <c>true</c>, checkbox is initially checked. Ignore if named value is found in submitted data. Finally
/// fall back to an existing "checked" value in <paramref name="htmlAttributes"/>.
/// </param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString CheckBox(string name, bool? isChecked, object htmlAttributes);
/// <summary> /// <summary>
/// Render an input element of type "checkbox" with value "true" and an input element of type "hidden" with /// Render an input element of type "checkbox" with value "true" and an input element of type "hidden" with
@ -125,71 +29,27 @@ namespace Microsoft.AspNet.Mvc.Rendering
HtmlString CheckBoxFor([NotNull] Expression<Func<TModel, bool>> expression, object htmlAttributes); HtmlString CheckBoxFor([NotNull] Expression<Func<TModel, bool>> expression, object htmlAttributes);
/// <summary> /// <summary>
/// Returns HTML markup for each property in the object that is represented by the expression, using the specified /// Returns HTML markup for each property in the object that is represented by the specified expression, using
/// template, HTML field ID, and additional view data. /// the template, an HTML field ID, and additional view data.
/// </summary>
/// <param name="expression">An expression that identifies the object that contains the properties to display.</param>
/// <param name="templateName">The name of the template that is used to render the object.</param>
/// <param name="htmlFieldName">
/// A string that is used to disambiguate the names of HTML input elements that are rendered for properties that have
/// the same name.
/// </param>
/// <param name="additionalViewData">
/// An anonymous object or dictionary that can contain additional view data that will be merged into the
/// <see cref="ViewDataDictionary{TModel}"/> instance that is created for the template.
/// </param>
/// <returns>The HTML markup for each property in the object that is represented by the expression.</returns>
HtmlString Display(string expression,
string templateName,
string htmlFieldName,
object additionalViewData);
/// <summary>
/// Returns HTML markup for each property in the object that is represented by the specified expression, using the
/// template, an HTML field ID, and additional view data.
/// </summary> /// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="expression">An expression that identifies the object that contains the properties to display.</param> /// <param name="expression">An expression that identifies the object that contains the properties to display.
/// </param>
/// <param name="templateName">The name of the template that is used to render the object.</param> /// <param name="templateName">The name of the template that is used to render the object.</param>
/// <param name="htmlFieldName"> /// <param name="htmlFieldName">
/// A string that is used to disambiguate the names of HTML input elements that are rendered for properties that have /// A string that is used to disambiguate the names of HTML input elements that are rendered for properties
/// the same name. /// that have the same name.
/// </param> /// </param>
/// <param name="additionalViewData"> /// <param name="additionalViewData">
/// An anonymous object or dictionary that can contain additional view data that will be merged into the /// An anonymous object or dictionary that can contain additional view data that will be merged into the
/// <see cref="ViewDataDictionary{TModel}"/> instance that is created for the template. /// <see cref="ViewDataDictionary{TModel}"/> instance that is created for the template.
/// </param> /// </param>
/// <returns>The HTML markup for each property in the object that is represented by the expression.</returns> /// <returns>The HTML markup for each property in the object that is represented by the expression.</returns>
HtmlString DisplayFor<TValue>(Expression<Func<TModel, TValue>> expression, HtmlString DisplayFor<TValue>([NotNull] Expression<Func<TModel, TValue>> expression,
string templateName, string templateName,
string htmlFieldName, string htmlFieldName,
object additionalViewData); object additionalViewData);
/// <summary>
/// Returns HTML markup for each property in the model, using the specified template, an HTML field ID, and additional
/// view data.
/// </summary>
/// <param name="templateName">The name of the template that is used to render the object.</param>
/// <param name="htmlFieldName">
/// A string that is used to disambiguate the names of HTML input elements that are rendered for properties that have the
/// same name.
/// </param>
/// <param name="additionalViewData">
/// An anonymous object or dictionary that can contain additional view data that will be merged into the
/// <see cref="ViewDataDictionary{TModel}"/> instance that is created for the template.
/// </param>
/// <returns>The HTML markup for each property in the model.</returns>
HtmlString DisplayForModel(string templateName, string htmlFieldName, object additionalViewData);
/// <summary>
/// Gets the display name.
/// </summary>
/// <param name="expression">An expression that identifies the object that contains the display name.</param>
/// <returns>
/// The display name.
/// </returns>
HtmlString DisplayName(string expression);
/// <summary> /// <summary>
/// Gets the display name for the model. /// Gets the display name for the model.
/// </summary> /// </summary>
@ -198,7 +58,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns> /// <returns>
/// The display name for the model. /// The display name for the model.
/// </returns> /// </returns>
HtmlString DisplayNameFor<TValue>(Expression<Func<TModel, TValue>> expression); HtmlString DisplayNameFor<TValue>([NotNull] Expression<Func<TModel, TValue>> expression);
/// <summary> /// <summary>
/// Gets the display name for the inner model if the current model represents a collection. /// Gets the display name for the inner model if the current model represents a collection.
@ -207,25 +67,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TValue">The type of the value.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="expression">An expression that identifies the object that contains the display name.</param> /// <param name="expression">An expression that identifies the object that contains the display name.</param>
/// <returns>The display name for the inner model.</returns> /// <returns>The display name for the inner model.</returns>
HtmlString DisplayNameForInnerType<TInnerModel, TValue>(Expression<Func<TInnerModel, TValue>> expression); HtmlString DisplayNameForInnerType<TInnerModel, TValue>(
[NotNull] Expression<Func<TInnerModel, TValue>> expression);
/// <summary>
/// Returns a single-selection HTML {select} element using the specified name of the form field,
/// list items, option label, and HTML attributes.
/// </summary>
/// <param name="name">The name of the form field to return.</param>
/// <param name="selectList">A collection of <see href="SelectListItem"/> objects that are used to populate the
/// drop-down list.</param>
/// <param name="optionLabel">The text for a default empty item. This parameter can be null.</param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the {select} element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>An HTML {select} element with an {option} subelement for each item in the list.</returns>
HtmlString DropDownList(
string name,
IEnumerable<SelectListItem> selectList,
string optionLabel,
object htmlAttributes);
/// <summary> /// <summary>
/// Returns a single-selection HTML {select} element for the object that is represented /// Returns a single-selection HTML {select} element for the object that is represented
@ -246,51 +89,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
string optionLabel, string optionLabel,
object htmlAttributes); object htmlAttributes);
/// <summary>
/// Converts the value of the specified object to an HTML-encoded string.
/// </summary>
/// <param name="value">The object to encode.</param>
/// <returns>The HTML-encoded string.</returns>
string Encode(object value);
/// <summary>
/// Converts the specified string to an HTML-encoded string.
/// </summary>
/// <param name="value">The string to encode.</param>
/// <returns>The HTML-encoded string.</returns>
string Encode(string value);
/// <summary>
/// Formats the value.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="format">The format string.</param>
/// <returns>The formatted value.</returns>
string FormatValue(object value, string format);
/// <summary>
/// Creates an HTML element ID using the specified element name.
/// </summary>
/// <param name="name">The name of the HTML element.</param>
/// <returns>The ID of the HTML element.</returns>
string GenerateIdFromName(string name);
/// <summary>
/// Render an input element of type "hidden".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="value">
/// If non-<c>null</c>, value to include in the element. Ignore if named value is found in submitted data.
/// </param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString Hidden(string name, object value, object htmlAttributes);
/// <summary> /// <summary>
/// Render an input element of type "hidden". /// Render an input element of type "hidden".
/// </summary> /// </summary>
@ -305,36 +103,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
object htmlAttributes); object htmlAttributes);
/// <summary> /// <summary>
/// Returns an HTML label element and the property name of the property that is represented by the specified expression. /// Returns an HTML label element and the property name of the property that is represented by the specified
/// </summary> /// expression.
/// <param name="expression">An expression that identifies the property to display.</param>
/// <param name="labelText">The label text.</param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
/// <returns>
/// An HTML label element and the property name of the property that is represented by the expression.
/// </returns>
HtmlString Label(string expression, string labelText, object htmlAttributes);
/// <summary>
/// Returns an HTML label element and the property name of the property that is represented by the specified expression.
/// </summary> /// </summary>
/// <param name="expression">An expression that identifies the property to display.</param> /// <param name="expression">An expression that identifies the property to display.</param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param> /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
/// <typeparam name="TValue">The type of the value.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam>
/// <returns> /// <returns>
/// An HTML label element and the property name of the property that is represented by the expression. /// An HTML label element and the property name of the property that is represented by the expression.
/// </returns> /// </returns>
HtmlString LabelFor<TValue>(Expression<Func<TModel, TValue>> expression, HtmlString LabelFor<TValue>([NotNull] Expression<Func<TModel, TValue>> expression,
string labelText, string labelText,
object htmlAttributes); object htmlAttributes);
/// <summary>
/// Gets the full HTML field name for the given expression <paramref name="name"/>.
/// </summary>
/// <param name="name">Name of an expression, relative to the current model.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString Name(string name);
/// <summary> /// <summary>
/// Gets the full HTML field name for the given <paramref name="expression"/>. /// Gets the full HTML field name for the given <paramref name="expression"/>.
/// </summary> /// </summary>
@ -343,22 +124,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns> /// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString NameFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression); HtmlString NameFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression);
/// <summary>
/// Render an input element of type "password".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="value">
/// If non-<c>null</c>, value to include in the element.
/// </param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString Password(string name, object value, object htmlAttributes);
/// <summary> /// <summary>
/// Render an input element of type "password". /// Render an input element of type "password".
/// </summary> /// </summary>
@ -372,30 +137,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
HtmlString PasswordFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression, HtmlString PasswordFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression,
object htmlAttributes); object htmlAttributes);
/// <summary>
/// Render an input element of type "radio".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="value">
/// If non-<c>null</c>, value to include in the element. May be <c>null</c> only if
/// <paramref name="isChecked"/> is also <c>null</c>. Also compared to value in submitted data or view data to
/// determine <paramref name="isChecked"/> if that parameter is <c>null</c>. Ignore if named value is found in
/// submitted data.
/// </param>
/// <param name="isChecked">
/// If <c>true</c>, radio button is initially selected. Ignore if named value is found in submitted data. Fall
/// back to comparing <paramref name="value"/> with view data if this parameter is <c>null</c>. Finally
/// fall back to an existing "checked" value in <paramref name="htmlAttributes"/>.
/// </param>
/// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.
/// Alternatively, an <see cref="IDictionary{string, object}"/> instance containing the HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString RadioButton(string name, object value, bool? isChecked, object htmlAttributes);
/// <summary> /// <summary>
/// Render an input element of type "radio". /// Render an input element of type "radio".
/// </summary> /// </summary>
@ -413,57 +154,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
HtmlString RadioButtonFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression, object value, HtmlString RadioButtonFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression, object value,
object htmlAttributes); object htmlAttributes);
/// <summary>
/// Wraps HTML markup in an <see cref="HtmlString"/>, which will enable HTML markup to be
/// rendered to the output without getting HTML encoded.
/// </summary>
/// <param name="value">HTML markup string.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString Raw(string value);
/// <summary>
/// Wraps HTML markup from the string representation of an object in an <see cref="HtmlString"/>,
/// which will enable HTML markup to be rendered to the output without getting HTML encoded.
/// </summary>
/// <param name="value">object with string representation as HTML markup.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString Raw(object value);
/// <summary>
/// Returns a partial view in string format.
/// </summary>
/// <param name="partialViewName">The name of the partial view to render and return.</param>
/// <param name="model">A model to pass into the partial view.</param>
/// <param name="viewData">A <see cref="ViewDataDictionary"/> to pass into the partial view.</param>
/// <returns>A task that represents when rendering of the partial view into a string has completed.</returns>
Task<HtmlString> PartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData);
/// <summary>
/// Renders a partial view.
/// </summary>
/// <param name="partialViewName">The name of the partial view to render.</param>
/// <param name="model">A model to pass into the partial view.</param>
/// <param name="viewData">A <see cref="ViewDataDictionary"/> to pass into the partial view.</param>
/// <returns>A task that represents when rendering has completed.</returns>
Task RenderPartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData);
/// <summary>
/// Render an input element of type "text".
/// </summary>
/// <param name="name">
/// Rendered element's name. Also use this name to find value in submitted data or view data. Use view data
/// only if value is not in submitted data and <paramref name="value"/> is <c>null</c>.
/// </param>
/// <param name="value">
/// If non-<c>null</c>, value to include in the element. Ignore if named value is found in submitted data.
/// </param>
/// <param name="format"></param>
/// <param name="htmlAttributes">
/// <see cref="IDictionary{string, object}"/> containing additional HTML attributes.
/// </param>
/// <returns>New <see cref="HtmlString"/> containing the rendered HTML.</returns>
HtmlString TextBox(string name, object value, string format, IDictionary<string, object> htmlAttributes);
/// <summary> /// <summary>
/// Render an input element of type "text". /// Render an input element of type "text".
/// </summary> /// </summary>
@ -478,27 +168,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
HtmlString TextBoxFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression, string format, HtmlString TextBoxFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression, string format,
IDictionary<string, object> htmlAttributes); IDictionary<string, object> htmlAttributes);
/// <summary>
/// Returns an unordered list (ul element) of validation messages that are in the
/// <see cref="ModelStateDictionary"/> object.
/// </summary>
/// <param name="excludePropertyErrors">true to have the summary display model-level errors only, or false to
/// have the summary display all errors.</param>
/// <param name="message">The message to display with the validation summary.</param>
/// <param name="htmlAttributes">A dictionary that contains the HTML attributes for the element.</param>
/// <returns>An <see cref="HtmlString"/> that contains an unordered list (ul element) of validation messages.
/// </returns>
HtmlString ValidationSummary(bool excludePropertyErrors, string message,
IDictionary<string, object> htmlAttributes);
/// <summary>
/// Returns the model value for the given expression <paramref name="name"/>.
/// </summary>
/// <param name="name">Name of an expression, relative to the current model.</param>
/// <param name="format">The optional format string to apply to the value.</param>
/// <returns>An <see cref="HtmlString"/> that represents HTML markup.</returns>
HtmlString Value([NotNull] string name, string format);
/// <summary> /// <summary>
/// Returns the model value for the given expression <paramref name="expression"/>. /// Returns the model value for the given expression <paramref name="expression"/>.
/// </summary> /// </summary>

View File

@ -9,7 +9,6 @@ using Microsoft.AspNet.Mvc.Razor;
using Microsoft.AspNet.Mvc.Razor.Compilation; using Microsoft.AspNet.Mvc.Razor.Compilation;
using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Security.Authorization; using Microsoft.AspNet.Security.Authorization;
using Microsoft.AspNet.Security.DataProtection;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -97,6 +96,7 @@ namespace Microsoft.AspNet.Mvc
implementationInstance: null, implementationInstance: null,
lifecycle: LifecycleKind.Transient); lifecycle: LifecycleKind.Transient);
yield return describe.Transient<IHtmlHelper, HtmlHelper>();
yield return yield return
describe.Describe( describe.Describe(
typeof(IHtmlHelper<>), typeof(IHtmlHelper<>),