You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
The default HTML template for a POCO object examines the IHtmlHelper.Label() return value using !string.IsNullOrEmpty(label.ToString()). This condition assumes all IHtmlContent implementations override ToString(). Further the condition works only as long as ToString() returns string.Empty when the IHtmlContent implementation will no-op in its WriteTo() method.
This problem does not show symptoms when using the default Label() implementation. That method always returns either HtmlString.Empty or a TagBuilder. HtmlString.Empty.ToString() returns the empty string. TagBuilder.ToString() always returns the type's FullName and TagBuilder.WriteTo() always writes something - at least angle brackets and the tag name. So, things appear to work at the moment.
Example cases where the current assumptions would be invalid:
We update TagBuilder to have a new TagRenderMode.Empty but still do not override ToString().
In 2.0, we remove the HtmlString.ToString() override because it's redundant with HtmlString.Value and maintained only for back-compat.
Users subclass HtmlHelper and override the GenerateLabel() method to return their own IHtmlContent implementation. That implementation does not satisfy our assumptions. (The assumptions aren't contractual or enforced of course.)
Side note: The default IHtmlHelper.Label() implementation rarely returns HtmlString.Empty but it definitely can do so. E.g. a property may have [Display(Name = "")].
The text was updated successfully, but these errors were encountered:
- #5317
- worked only because `TagBuilder` cannot be empty and `HtmlString` overrides `ToString()`
- `TagBuilder.ToString()` (now the type's `FullName`) is also never empty
- #5317
- worked only because `TagBuilder` cannot be empty and `HtmlString` overrides `ToString()`
- `TagBuilder.ToString()` (now the type's `FullName`) is also never empty
- #5317
- previously worked only because `TagBuilder` cannot be empty and `HtmlString` overrides `ToString()`
- `TagBuilder.ToString()` (now the type's `FullName`) is also never empty
- copy `NullHtmlEncoder` from Razor and give it a better name (`PassThroughHtmlEncoder`)
- not available in this project and (from its namespace) not intended for general use
The default HTML template for a POCO object examines the
IHtmlHelper.Label()
return value using!string.IsNullOrEmpty(label.ToString())
. This condition assumes allIHtmlContent
implementations overrideToString()
. Further the condition works only as long asToString()
returnsstring.Empty
when theIHtmlContent
implementation will no-op in itsWriteTo()
method.This problem does not show symptoms when using the default
Label()
implementation. That method always returns eitherHtmlString.Empty
or aTagBuilder
.HtmlString.Empty.ToString()
returns the empty string.TagBuilder.ToString()
always returns the type'sFullName
andTagBuilder.WriteTo()
always writes something - at least angle brackets and the tag name. So, things appear to work at the moment.Example cases where the current assumptions would be invalid:
TagBuilder
to have a newTagRenderMode.Empty
but still do not overrideToString()
.HtmlString.ToString()
override because it's redundant withHtmlString.Value
and maintained only for back-compat.HtmlHelper
and override theGenerateLabel()
method to return their ownIHtmlContent
implementation. That implementation does not satisfy our assumptions. (The assumptions aren't contractual or enforced of course.)Side note: The default
IHtmlHelper.Label()
implementation rarely returnsHtmlString.Empty
but it definitely can do so. E.g. a property may have[Display(Name = "")]
.The text was updated successfully, but these errors were encountered: