Addressed code review comments.
This commit is contained in:
parent
5026788145
commit
671c7dd59e
|
|
@ -1 +1,5 @@
|
||||||
<p>This is the DisplayForModel output. Once default templates are implemented this should go away.</p>
|
@using System.Linq
|
||||||
|
|
||||||
|
<p>This is the DisplayForModel output. Once default templates are implemented this should go away.</p>
|
||||||
|
<p><strong>User Name: </strong>@ViewData.Model.Name</p>
|
||||||
|
<p><strong>User Model Metadata Property Count: </strong>@ViewData.ModelMetadata.Properties.Count()</p>
|
||||||
|
|
@ -163,33 +163,26 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
}
|
}
|
||||||
|
|
||||||
public HtmlString Display(string expression,
|
public HtmlString Display(string expression,
|
||||||
string templateName,
|
string templateName,
|
||||||
string htmlFieldName,
|
string htmlFieldName,
|
||||||
object additionalViewData)
|
object additionalViewData)
|
||||||
{
|
{
|
||||||
var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
|
var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
|
||||||
|
|
||||||
return GenerateDisplay(metadata,
|
return GenerateDisplay(metadata,
|
||||||
htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
|
htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
|
||||||
templateName,
|
templateName,
|
||||||
additionalViewData);
|
additionalViewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual HtmlString DisplayForModel(string templateName,
|
public HtmlString DisplayForModel(string templateName,
|
||||||
string htmlFieldName,
|
string htmlFieldName,
|
||||||
object additionalViewData)
|
object additionalViewData)
|
||||||
{
|
{
|
||||||
var templateBuilder = new TemplateBuilder(ViewContext,
|
return GenerateDisplay(ViewData.ModelMetadata,
|
||||||
ViewData,
|
htmlFieldName,
|
||||||
ViewData.ModelMetadata,
|
templateName,
|
||||||
htmlFieldName,
|
additionalViewData);
|
||||||
templateName,
|
|
||||||
readOnly: true,
|
|
||||||
additionalViewData: additionalViewData);
|
|
||||||
|
|
||||||
var templateResult = templateBuilder.Build();
|
|
||||||
|
|
||||||
return new HtmlString(templateResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,35 @@
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Rendering
|
namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
{
|
{
|
||||||
public static class DisplayForModelExtensions
|
public static class HtmlHelperDisplayForModelExtensions
|
||||||
{
|
{
|
||||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html)
|
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html)
|
||||||
{
|
{
|
||||||
return html.DisplayForModel(templateName: null, htmlFieldName: null, additionalViewData: null);
|
return html.DisplayForModel(templateName: null, htmlFieldName: null, additionalViewData: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html, object additionalViewData)
|
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
object additionalViewData)
|
||||||
{
|
{
|
||||||
return html.DisplayForModel(templateName: null, htmlFieldName: null, additionalViewData: additionalViewData);
|
return html.DisplayForModel(templateName: null, htmlFieldName: null, additionalViewData: additionalViewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html, string templateName)
|
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
string templateName)
|
||||||
{
|
{
|
||||||
return html.DisplayForModel(templateName, htmlFieldName: null, additionalViewData: null);
|
return html.DisplayForModel(templateName, htmlFieldName: null, additionalViewData: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html, string templateName, object additionalViewData)
|
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
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>(this IHtmlHelper<TModel> html, string templateName, string htmlFieldName)
|
public static HtmlString DisplayForModel<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
string templateName,
|
||||||
|
string htmlFieldName)
|
||||||
{
|
{
|
||||||
return html.DisplayForModel(templateName, htmlFieldName, additionalViewData: null);
|
return html.DisplayForModel(templateName, htmlFieldName, additionalViewData: null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,16 +69,23 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
/// </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>(Expression<Func<TModel, TValue>> expression,
|
||||||
string templateName,
|
string templateName,
|
||||||
string htmlFieldName,
|
string htmlFieldName,
|
||||||
object additionalViewData);
|
object additionalViewData);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns HTML markup for each property in the model, using the specified template, an HTML field ID, and additional view data.
|
/// Returns HTML markup for each property in the model, using the specified template, an HTML field ID, and additional
|
||||||
|
/// view data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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 model.</returns>
|
/// <returns>The HTML markup for each property in the model.</returns>
|
||||||
HtmlString DisplayForModel(string templateName, string htmlFieldName, object additionalViewData);
|
HtmlString DisplayForModel(string templateName, string htmlFieldName, object additionalViewData);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue