Implement DisplayForModel Html Helper.
Essentially add extension methods and call through to infrastructure.
This commit is contained in:
parent
4f67dee048
commit
1f47abd758
|
|
@ -175,6 +175,23 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
additionalViewData);
|
||||
}
|
||||
|
||||
public virtual HtmlString DisplayForModel(string templateName,
|
||||
string htmlFieldName,
|
||||
object additionalViewData)
|
||||
{
|
||||
var templateBuilder = new TemplateBuilder(ViewContext,
|
||||
ViewData,
|
||||
ViewData.ModelMetadata,
|
||||
htmlFieldName,
|
||||
templateName,
|
||||
readOnly: true,
|
||||
additionalViewData: additionalViewData);
|
||||
|
||||
var templateResult = templateBuilder.Build();
|
||||
|
||||
return new HtmlString(templateResult);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual HtmlString Name(string name)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
{
|
||||
public static class DisplayForModelExtensions
|
||||
{
|
||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html)
|
||||
{
|
||||
return html.DisplayForModel(templateName: null, htmlFieldName: null, additionalViewData: null);
|
||||
}
|
||||
|
||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html, object additionalViewData)
|
||||
{
|
||||
return html.DisplayForModel(templateName: null, htmlFieldName: null, additionalViewData: additionalViewData);
|
||||
}
|
||||
|
||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html, string templateName)
|
||||
{
|
||||
return html.DisplayForModel(templateName, htmlFieldName: null, additionalViewData: null);
|
||||
}
|
||||
|
||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html, string templateName, object additionalViewData)
|
||||
{
|
||||
return html.DisplayForModel(templateName, htmlFieldName: null, additionalViewData: additionalViewData);
|
||||
}
|
||||
|
||||
public static HtmlString DisplayForModel<TModel>(this IHtmlHelper<TModel> html, string templateName, string htmlFieldName)
|
||||
{
|
||||
return html.DisplayForModel(templateName, htmlFieldName, additionalViewData: null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -73,6 +73,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
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 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>
|
||||
/// Converts the value of the specified object to an HTML-encoded string.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue