diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelper.cs index 0a15584962..a07db32585 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelper.cs @@ -258,17 +258,16 @@ public HtmlString DisplayForModel(string templateName, } /// - public HtmlString DisplayName(string expression) + public string DisplayName(string expression) { var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider); return GenerateDisplayName(metadata, expression); } /// - public HtmlString DisplayText(string name) + public string DisplayText(string name) { var metadata = ExpressionMetadataProvider.FromStringExpression(name, ViewData, MetadataProvider); - return GenerateDisplayText(metadata); } @@ -305,7 +304,7 @@ public HtmlString Hidden(string name, object value, object htmlAttributes) } /// - public HtmlString Id(string name) + public string Id(string name) { return GenerateId(name); } @@ -328,10 +327,10 @@ public HtmlString ListBox(string name, IEnumerable selectList, o } /// - public virtual HtmlString Name(string name) + public virtual string Name(string name) { var fullName = ViewData.TemplateInfo.GetFullHtmlFieldName(name); - return new HtmlString(Encode(fullName)); + return fullName; } /// @@ -585,7 +584,7 @@ public HtmlString TextBox(string name, object value, string format, IDictionary< } /// - public HtmlString Value([NotNull] string name, string format) + public string Value([NotNull] string name, string format) { return GenerateValue(name, value: null, format: format, useViewData: true); } @@ -701,7 +700,7 @@ protected virtual HtmlString GenerateCheckBox(ModelMetadata metadata, string nam htmlAttributes: htmlAttributeDictionary); } - protected virtual HtmlString GenerateDisplayName([NotNull] ModelMetadata metadata, string htmlFieldName) + protected virtual string GenerateDisplayName([NotNull] ModelMetadata metadata, string htmlFieldName) { // We don't call ModelMetadata.GetDisplayName here because // we want to fall back to the field name rather than the ModelType. @@ -713,12 +712,12 @@ protected virtual HtmlString GenerateDisplayName([NotNull] ModelMetadata metadat string.IsNullOrEmpty(htmlFieldName) ? string.Empty : htmlFieldName.Split('.').Last(); } - return new HtmlString(Encode(resolvedDisplayName)); + return resolvedDisplayName; } - protected virtual HtmlString GenerateDisplayText(ModelMetadata metadata) + protected virtual string GenerateDisplayText(ModelMetadata metadata) { - return new HtmlString(metadata.SimpleDisplayText); + return metadata.SimpleDisplayText ?? string.Empty; } protected HtmlString GenerateDropDown(ModelMetadata metadata, string expression, @@ -845,9 +844,9 @@ protected virtual HtmlString GenerateHidden( htmlAttributes: htmlAttributeDictionary); } - protected virtual HtmlString GenerateId(string expression) + protected virtual string GenerateId(string expression) { - return new HtmlString(Encode(ViewData.TemplateInfo.GetFullHtmlFieldName(expression))); + return ViewData.TemplateInfo.GetFullHtmlFieldName(expression); } protected virtual HtmlString GenerateLabel([NotNull] ModelMetadata metadata, @@ -1344,7 +1343,7 @@ protected virtual HtmlString GenerateValidationMessage(string expression, return builder.ToHtmlString(TagRenderMode.Normal); } - protected virtual HtmlString GenerateValue(string name, object value, string format, bool useViewData) + protected virtual string GenerateValue(string name, object value, string format, bool useViewData) { var fullName = ViewData.TemplateInfo.GetFullHtmlFieldName(name); var attemptedValue = (string)GetModelStateValue(fullName, typeof(string)); @@ -1375,7 +1374,7 @@ protected virtual HtmlString GenerateValue(string name, object value, string for resolvedValue = FormatValue(value, format); } - return new HtmlString(Encode(resolvedValue)); + return resolvedValue; } protected virtual IEnumerable GetClientValidationRules( diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs index f52d9932cf..390b5d43a6 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs @@ -88,14 +88,14 @@ public HtmlString DisplayFor([NotNull] Expression> } /// - public HtmlString DisplayNameFor([NotNull] Expression> expression) + public string DisplayNameFor([NotNull] Expression> expression) { var metadata = GetModelMetadata(expression); return GenerateDisplayName(metadata, ExpressionHelper.GetExpressionText(expression)); } /// - public HtmlString DisplayNameForInnerType( + public string DisplayNameForInnerType( [NotNull] Expression> expression) { var metadata = ExpressionMetadataProvider.FromLambdaExpression( @@ -113,7 +113,7 @@ public HtmlString DisplayNameForInnerType( } /// - public HtmlString DisplayTextFor([NotNull] Expression> expression) + public string DisplayTextFor([NotNull] Expression> expression) { return GenerateDisplayText(GetModelMetadata(expression)); } @@ -144,7 +144,7 @@ public HtmlString HiddenFor([NotNull] Expression - public HtmlString IdFor([NotNull] Expression> expression) + public string IdFor([NotNull] Expression> expression) { return GenerateId(GetExpressionName(expression)); } @@ -172,7 +172,7 @@ public HtmlString ListBoxFor( } /// - public HtmlString NameFor([NotNull] Expression> expression) + public string NameFor([NotNull] Expression> expression) { var expressionName = GetExpressionName(expression); return Name(expressionName); @@ -242,7 +242,7 @@ public HtmlString ValidationMessageFor([NotNull] Expression - public HtmlString ValueFor(Expression> expression, string format) + public string ValueFor(Expression> expression, string format) { var metadata = GetModelMetadata(expression); return GenerateValue(ExpressionHelper.GetExpressionText(expression), metadata.Model, format, diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperDisplayNameExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperDisplayNameExtensions.cs index cb40f12361..f0224e05eb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperDisplayNameExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperDisplayNameExtensions.cs @@ -15,21 +15,19 @@ public static class HtmlHelperDisplayNameExtensions /// /// Gets the display name for the current model. /// - /// An that represents HTML markup. - public static HtmlString DisplayNameForModel([NotNull] this IHtmlHelper htmlHelper) + /// The display name. + public static string DisplayNameForModel([NotNull] this IHtmlHelper htmlHelper) { return htmlHelper.DisplayName(string.Empty); } /// - /// Gets the display name for the model. + /// Gets the display name. /// /// The instance that this method extends. /// An expression that identifies the object that contains the display name. - /// - /// The display name for the model. - /// - public static HtmlString DisplayNameFor( + /// The display name. + public static string DisplayNameFor( [NotNull] this IHtmlHelper> htmlHelper, [NotNull] Expression> expression) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperNameExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperNameExtensions.cs index 2d46b7ff0e..77af5d0beb 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperNameExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperNameExtensions.cs @@ -12,18 +12,18 @@ public static class HtmlHelperNameExtensions /// Gets the full HTML field name for the current model. /// /// The instance that this method extends. - /// An that represents HTML markup. - public static HtmlString NameForModel([NotNull] this IHtmlHelper htmlHelper) + /// The name. + public static string NameForModel([NotNull] this IHtmlHelper htmlHelper) { return htmlHelper.Name(string.Empty); } /// - /// Gets the full HTML field id for the current model. + /// Gets the full HTML field Id for the current model. /// /// The instance that this method extends. - /// An that represents HTML markup. - public static HtmlString IdForModel([NotNull] this IHtmlHelper htmlHelper) + /// The Id of the HTML element. + public static string IdForModel([NotNull] this IHtmlHelper htmlHelper) { return htmlHelper.Id(string.Empty); } diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperValueExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperValueExtensions.cs index 0eea6e8b82..dd41245ed9 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperValueExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/HtmlHelperValueExtensions.cs @@ -8,24 +8,47 @@ namespace Microsoft.AspNet.Mvc.Rendering { public static class HtmlHelperValueExtensions { - public static HtmlString Value([NotNull] this IHtmlHelper htmlHelper, string name) + /// + /// Returns the model value for the given expression . + /// + /// The instance that this method extends. + /// Name of an expression, relative to the current model. + /// The value. + public static string Value([NotNull] this IHtmlHelper htmlHelper, string name) { return htmlHelper.Value(name, format: null); } - public static HtmlString ValueFor( + /// + /// Returns the model value for the given . + /// + /// The instance that this method extends. + /// An expression, relative to the current model. + /// The value. + public static string ValueFor( [NotNull] this IHtmlHelper htmlHelper, [NotNull] Expression> expression) { return htmlHelper.ValueFor(expression, format: null); } - public static HtmlString ValueForModel([NotNull] this IHtmlHelper htmlHelper) + /// + /// Returns the model value for the current model. + /// + /// The instance that this method extends. + /// The value. + public static string ValueForModel([NotNull] this IHtmlHelper htmlHelper) { return ValueForModel(htmlHelper, format: null); } - public static HtmlString ValueForModel([NotNull] this IHtmlHelper htmlHelper, string format) + /// + /// Returns the model value for the current model. + /// + /// The instance that this method extends. + /// The optional format string to apply to the value. + /// The value. + public static string ValueForModel([NotNull] this IHtmlHelper htmlHelper, string format) { return htmlHelper.Value(string.Empty, format); } diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelper.cs index 2ce1b6c12c..76213fa736 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelper.cs @@ -162,17 +162,16 @@ HtmlString Display( /// /// The display name. /// - HtmlString DisplayName(string expression); + string DisplayName(string expression); - /// Returns the HtmlString corresponding to the property in the model specified by the name. + /// + /// Gets the display text for the specified expression . /// - /// - /// The string which identifies the object for which the HtmlString should be returned. + /// Name of an expression, relative to the current model. /// - /// New containing the display text. If the value is null, - /// then it returns the ModelMetadata.NullDisplayText. + /// The display text. If the value is null, returns . /// - HtmlString DisplayText(string name); + string DisplayText(string name); /// /// Returns a single-selection HTML {select} element using the specified name of the form field, @@ -262,11 +261,11 @@ HtmlString DropDownList( HtmlString Hidden(string name, object value, object htmlAttributes); /// - /// Gets the Id of the given string. + /// Gets the HTML element Id for the specified expression . /// - /// The string which identifies the object for which the Id should be returned. - /// New containing the Id. - HtmlString Id(string name); + /// Name of an expression, relative to the current model. + /// The Id of the HTML element. + string Id(string name); /// /// Returns an HTML label element and the property name of the property that is represented by the specified @@ -294,11 +293,11 @@ HtmlString DropDownList( HtmlString ListBox(string name, IEnumerable selectList, object htmlAttributes); /// - /// Gets the full HTML field name for the given expression . + /// Gets the full HTML element name for the given expression . /// /// Name of an expression, relative to the current model. - /// An that represents HTML markup. - HtmlString Name(string name); + /// The name. + string Name(string name); /// /// Returns a partial view in string format. @@ -475,7 +474,7 @@ HtmlString ValidationSummary( /// /// Name of an expression, relative to the current model. /// The optional format string to apply to the value. - /// An that represents HTML markup. - HtmlString Value([NotNull] string name, string format); + /// The value. + string Value([NotNull] string name, string format); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelperOfT.cs index 7b934507cd..b026139f4b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/IHtmlHelperOfT.cs @@ -54,14 +54,14 @@ HtmlString DisplayFor([NotNull] Expression> express object additionalViewData); /// - /// Gets the display name for the model. + /// Gets the display name. /// /// An expression that identifies the object that contains the display name. /// The type of the value. /// - /// The display name for the model. + /// The display name. /// - HtmlString DisplayNameFor([NotNull] Expression> expression); + string DisplayNameFor([NotNull] Expression> expression); /// /// Gets the display name for the inner model if the current model represents a collection. @@ -70,20 +70,19 @@ HtmlString DisplayFor([NotNull] Expression> express /// The type of the value. /// An expression that identifies the object that contains the display name. /// The display name for the inner model. - HtmlString DisplayNameForInnerType( + string DisplayNameForInnerType( [NotNull] Expression> expression); /// - /// Returns the HtmlString corresponding to the expression specified. + /// Gets the display text for the specified . /// /// - /// The expression identifies the object for which the HtmlString should be returned. + /// The expression identifies the object for which the display text should be returned. /// /// - /// New containing the display text. If the value is null, - /// then it returns the ModelMetadata.NullDisplayText. + /// The display text. If the value is null, returns . /// - HtmlString DisplayTextFor([NotNull] Expression> expression); + string DisplayTextFor([NotNull] Expression> expression); /// /// Returns a single-selection HTML {select} element for the object that is represented @@ -141,11 +140,11 @@ HtmlString HiddenFor([NotNull] Expression> ex object htmlAttributes); /// - /// Gets the Id of the given expression. + /// Gets the HTML element Id for the specified . /// /// The expression identifies the object for which the Id should be returned. - /// New containing the Id. - HtmlString IdFor([NotNull] Expression> expression); + /// The Id of the HTML element. + string IdFor([NotNull] Expression> expression); /// /// Returns an HTML label element and the property name of the property that is represented by the specified @@ -180,12 +179,12 @@ HtmlString ListBoxFor( object htmlAttributes); /// - /// Gets the full HTML field name for the given . + /// Gets the full HTML element name for the given . /// /// The the returns. /// An expression, relative to the current model. - /// An that represents HTML markup. - HtmlString NameFor([NotNull] Expression> expression); + /// The name. + string NameFor([NotNull] Expression> expression); /// /// Render an input element of type "password". @@ -251,7 +250,7 @@ HtmlString TextBoxFor([NotNull] Expression> e /// The message to be displayed. This will always be visible but client-side /// validation may update the associated CSS class. /// An object that contains the HTML attributes to set for the element. - /// Alternatively, an /// instance containing the HTML attributes. + /// Alternatively, an instance containing the HTML attributes. /// /// The tag to wrap the in the generated HTML. /// Its default value is . @@ -262,11 +261,11 @@ HtmlString ValidationMessageFor([NotNull] Expression - /// Returns the model value for the given expression . + /// Returns the model value for the given . /// /// An expression, relative to the current model. /// The optional format string to apply to the value. - /// An that represents HTML markup. - HtmlString ValueFor([NotNull] Expression> expression, string format); + /// The value. + string ValueFor([NotNull] Expression> expression, string format); } }