Addressed code review comments
This commit is contained in:
parent
94bae850c7
commit
4f67dee048
|
|
@ -175,24 +175,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
additionalViewData);
|
additionalViewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual HtmlString DisplayFor<TModel, TValue>(Expression<Func<TModel, TValue>> expression,
|
|
||||||
string templateName,
|
|
||||||
string htmlFieldName,
|
|
||||||
object additionalViewData)
|
|
||||||
{
|
|
||||||
var templateBuilder = new TemplateBuilder(ViewContext,
|
|
||||||
ViewData,
|
|
||||||
ExpressionMetadataProvider.FromLambdaExpression(expression, (ViewDataDictionary<TModel>)ViewData, MetadataProvider),
|
|
||||||
htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
|
|
||||||
templateName,
|
|
||||||
readOnly: true,
|
|
||||||
additionalViewData: additionalViewData);
|
|
||||||
|
|
||||||
var templateResult = templateBuilder.Build();
|
|
||||||
|
|
||||||
return new HtmlString(templateResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual HtmlString Name(string name)
|
public virtual HtmlString Name(string name)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,22 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
base.Contextualize(viewContext);
|
base.Contextualize(viewContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public HtmlString DisplayFor<TValue>([NotNull] Expression<Func<TModel, TValue>> expression,
|
||||||
|
string templateName,
|
||||||
|
string htmlFieldName,
|
||||||
|
object additionalViewData)
|
||||||
|
{
|
||||||
|
var metadata = ExpressionMetadataProvider.FromLambdaExpression(expression,
|
||||||
|
ViewData,
|
||||||
|
MetadataProvider);
|
||||||
|
|
||||||
|
return GenerateDisplay(metadata,
|
||||||
|
htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
|
||||||
|
templateName,
|
||||||
|
additionalViewData);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public HtmlString NameFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression)
|
public HtmlString NameFor<TProperty>([NotNull] Expression<Func<TModel, TProperty>> expression)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,36 +4,42 @@ using System.Linq.Expressions;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Rendering
|
namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
{
|
{
|
||||||
public static class DisplayForExtensions
|
public static class HtmlHelperDisplayForExtensions
|
||||||
{
|
{
|
||||||
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")]
|
public static HtmlString DisplayFor<TModel, TValue>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
public static HtmlString DisplayFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
|
[NotNull] Expression<Func<TModel, TValue>> expression)
|
||||||
{
|
{
|
||||||
return html.DisplayFor<TModel, TValue>(expression, templateName: null, htmlFieldName: null, additionalViewData: null);
|
return html.DisplayFor<TValue>(expression, templateName: null, htmlFieldName: null, additionalViewData: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")]
|
public static HtmlString DisplayFor<TModel, TValue>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
public static HtmlString DisplayFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, object additionalViewData)
|
[NotNull] Expression<Func<TModel, TValue>> expression,
|
||||||
|
object additionalViewData)
|
||||||
{
|
{
|
||||||
return html.DisplayFor<TModel, TValue>(expression, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData);
|
return html.DisplayFor<TValue>(expression, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")]
|
public static HtmlString DisplayFor<TModel, TValue>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
public static HtmlString DisplayFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string templateName)
|
[NotNull] Expression<Func<TModel, TValue>> expression,
|
||||||
|
string templateName)
|
||||||
{
|
{
|
||||||
return html.DisplayFor<TModel, TValue>(expression, templateName, htmlFieldName: null, additionalViewData: null);
|
return html.DisplayFor<TValue>(expression, templateName, htmlFieldName: null, additionalViewData: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")]
|
public static HtmlString DisplayFor<TModel, TValue>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
public static HtmlString DisplayFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string templateName, object additionalViewData)
|
[NotNull] Expression<Func<TModel, TValue>> expression,
|
||||||
|
string templateName,
|
||||||
|
object additionalViewData)
|
||||||
{
|
{
|
||||||
return html.DisplayFor<TModel, TValue>(expression, templateName, htmlFieldName: null, additionalViewData: additionalViewData);
|
return html.DisplayFor<TValue>(expression, templateName, htmlFieldName: null, additionalViewData: additionalViewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")]
|
public static HtmlString DisplayFor<TModel, TValue>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
public static HtmlString DisplayFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string templateName, string htmlFieldName)
|
[NotNull] Expression<Func<TModel, TValue>> expression,
|
||||||
|
string templateName,
|
||||||
|
string htmlFieldName)
|
||||||
{
|
{
|
||||||
return html.DisplayFor<TModel, TValue>(expression, templateName: templateName, htmlFieldName: htmlFieldName, additionalViewData: null);
|
return html.DisplayFor<TValue>(expression, templateName: templateName, htmlFieldName: htmlFieldName, additionalViewData: null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,16 +52,23 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
object additionalViewData);
|
object additionalViewData);
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// 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="TDisplayModel">The type of the model.</typeparam>
|
/// <typeparam name="TDisplayModel">The type of the model.</typeparam>
|
||||||
/// <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">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="htmlFieldName">
|
||||||
/// <param name="additionalViewData">An anonymous object that can contain additional view data that will be merged into the <see cref="ViewDataDictionary{TModel}"/> instance that is created for the template.</param>
|
/// 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>
|
/// <returns>The HTML markup for each property in the object that is represented by the expression.</returns>
|
||||||
HtmlString DisplayFor<TDisplayModel, TValue>(Expression<Func<TDisplayModel, TValue>> expression,
|
HtmlString DisplayFor<TValue>(Expression<Func<TModel, TValue>> expression,
|
||||||
string templateName,
|
string templateName,
|
||||||
string htmlFieldName,
|
string htmlFieldName,
|
||||||
object additionalViewData);
|
object additionalViewData);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue