Addressed code review comments.
This commit is contained in:
parent
5dbd006165
commit
2b3687282e
|
|
@ -1,10 +1,12 @@
|
||||||
@functions {
|
@using System.Globalization
|
||||||
|
|
||||||
|
@functions {
|
||||||
private bool? Value {
|
private bool? Value {
|
||||||
get {
|
get {
|
||||||
if (ViewData.Model == null) {
|
if (ViewData.Model == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Convert.ToBoolean(ViewData.Model, System.Globalization.CultureInfo.InvariantCulture);
|
return Convert.ToBoolean(ViewData.Model, CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
@functions {
|
@using System.Globalization
|
||||||
|
|
||||||
|
@functions {
|
||||||
private object FormattedValue {
|
private object FormattedValue {
|
||||||
get {
|
get {
|
||||||
if (ViewData.TemplateInfo.FormattedModelValue == ViewData.ModelMetadata.Model) {
|
if (ViewData.TemplateInfo.FormattedModelValue == ViewData.ModelMetadata.Model) {
|
||||||
return String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:0.00}", ViewData.ModelMetadata.Model);
|
return String.Format(CultureInfo.CurrentCulture, "{0:0.00}", ViewData.ModelMetadata.Model);
|
||||||
}
|
}
|
||||||
return ViewData.TemplateInfo.FormattedModelValue;
|
return ViewData.TemplateInfo.FormattedModelValue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,12 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div style="float: left; border: 5px solid red;">
|
||||||
|
@await Component.InvokeAsync("Tags", 15)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
<div style="float: left; border: 5px solid green;">
|
<div style="float: left; border: 5px solid green;">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -256,8 +262,4 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="float: right; border: 5px solid red;">
|
|
||||||
@await Component.InvokeAsync("Tags", 15)
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -162,22 +162,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
return TagBuilder.CreateSanitizedId(name, IdAttributeDotReplacement);
|
return TagBuilder.CreateSanitizedId(name, IdAttributeDotReplacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual HtmlString Display(string expression,
|
public HtmlString Display(string expression,
|
||||||
string templateName,
|
string templateName,
|
||||||
string htmlFieldName,
|
string htmlFieldName,
|
||||||
object additionalViewData)
|
object additionalViewData)
|
||||||
{
|
{
|
||||||
var templateBuilder = new TemplateBuilder(ViewContext,
|
var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
|
||||||
ViewData,
|
|
||||||
ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider),
|
|
||||||
htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
|
|
||||||
templateName,
|
|
||||||
readOnly: true,
|
|
||||||
additionalViewData: additionalViewData);
|
|
||||||
|
|
||||||
var templateResult = templateBuilder.Build();
|
return GenerateDisplay(metadata,
|
||||||
|
htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
|
||||||
return new HtmlString(templateResult);
|
templateName,
|
||||||
|
additionalViewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
@ -203,6 +198,25 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
return RenderPartialCoreAsync(partialViewName, model, viewData, ViewContext.Writer);
|
return RenderPartialCoreAsync(partialViewName, model, viewData, ViewContext.Writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual HtmlString GenerateDisplay(ModelMetadata metadata,
|
||||||
|
string htmlFieldName,
|
||||||
|
string templateName,
|
||||||
|
object additionalViewData)
|
||||||
|
{
|
||||||
|
var templateBuilder = new TemplateBuilder(_viewEngine,
|
||||||
|
ViewContext,
|
||||||
|
ViewData,
|
||||||
|
metadata,
|
||||||
|
templateName,
|
||||||
|
templateName,
|
||||||
|
readOnly: true,
|
||||||
|
additionalViewData: additionalViewData);
|
||||||
|
|
||||||
|
var templateResult = templateBuilder.Build();
|
||||||
|
|
||||||
|
return new HtmlString(templateResult);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual async Task RenderPartialCoreAsync([NotNull] string partialViewName,
|
protected virtual async Task RenderPartialCoreAsync([NotNull] string partialViewName,
|
||||||
object model,
|
object model,
|
||||||
ViewDataDictionary viewData,
|
ViewDataDictionary viewData,
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,40 @@
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Rendering
|
namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
{
|
{
|
||||||
public static class DisplayExtensions
|
public static class HtmlHelperDisplayExtensions
|
||||||
{
|
{
|
||||||
public static HtmlString Display<T>(this IHtmlHelper<T> html, string expression)
|
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
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<T>(this IHtmlHelper<T> html, string expression, object additionalViewData)
|
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
string expression,
|
||||||
|
object additionalViewData)
|
||||||
{
|
{
|
||||||
return html.Display(expression, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData);
|
return html.Display(expression, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HtmlString Display<T>(this IHtmlHelper<T> html, string expression, string templateName)
|
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
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<T>(this IHtmlHelper<T> html, string expression, string templateName, object additionalViewData)
|
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
string expression,
|
||||||
|
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<T>(this IHtmlHelper<T> html, string expression, string templateName, string htmlFieldName)
|
public static HtmlString Display<TModel>([NotNull] this IHtmlHelper<TModel> html,
|
||||||
|
string expression,
|
||||||
|
string templateName,
|
||||||
|
string htmlFieldName)
|
||||||
{
|
{
|
||||||
return html.Display(expression, templateName, htmlFieldName, additionalViewData: null);
|
return html.Display(expression, templateName, htmlFieldName, additionalViewData: null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
/// <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>
|
||||||
{
|
{
|
||||||
/// <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 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>
|
/// <summary>
|
||||||
/// Gets or sets the character that replaces periods in the ID attribute of an element.
|
/// Gets or sets the character that replaces periods in the ID attribute of an element.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -44,6 +31,26 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ViewDataDictionary<TModel> ViewData { get; }
|
ViewDataDictionary<TModel> ViewData { get; }
|
||||||
|
|
||||||
|
/// <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>
|
/// <summary>
|
||||||
/// Converts the value of the specified object to an HTML-encoded string.
|
/// Converts the value of the specified object to an HTML-encoded string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue