diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs
index bf6f29f595..0492c4e77a 100644
--- a/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs
@@ -249,12 +249,12 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
output.Attributes.Clear();
output.TagName = null;
- output.Content.Append(tagBuilder.ToString(TagRenderMode.SelfClosing));
+ output.Content.Append(tagBuilder.ToHtmlContent(TagRenderMode.SelfClosing));
tagBuilder = Generator.GenerateHiddenForCheckbox(ViewContext, modelExplorer, For.Name);
if (tagBuilder != null)
{
- output.Content.Append(tagBuilder.ToString(TagRenderMode.SelfClosing));
+ output.Content.Append(tagBuilder.ToHtmlContent(TagRenderMode.SelfClosing));
}
}
}
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/BufferedHtmlContent.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/BufferedHtmlContent.cs
deleted file mode 100644
index 647c3700f9..0000000000
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/BufferedHtmlContent.cs
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using Microsoft.AspNet.Html.Abstractions;
-using Microsoft.Framework.Internal;
-using Microsoft.Framework.WebEncoders;
-
-namespace Microsoft.AspNet.Mvc.Rendering
-{
- ///
- /// Enumerable object collection which knows how to write itself.
- ///
- public class BufferedHtmlContent : IHtmlContent
- {
- private const int MaxCharToStringLength = 1024;
- // This is not List because that would lead to boxing all strings to IHtmlContent
- // which is not space performant.
- // internal for testing.
- internal List Entries { get; } = new List();
-
- ///
- /// Appends the string to the collection.
- ///
- /// The string to be appended.
- public void Append([NotNull] string value)
- {
- Entries.Add(value);
- }
-
- ///
- /// Appends a character array to the collection.
- ///
- /// The character array to be appended.
- /// The index from which the character array must be read.
- /// The count till which the character array must be read.
- ///
- /// Splits the character array into strings of 1KB length and appends them.
- ///
- public void Append([NotNull] char[] value, int index, int count)
- {
- if (index < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(index));
- }
- if (count < 0 || value.Length - index < count)
- {
- throw new ArgumentOutOfRangeException(nameof(count));
- }
-
- while (count > 0)
- {
- // Split large char arrays into 1KB strings.
- var currentCount = count;
- if (MaxCharToStringLength < currentCount)
- {
- currentCount = MaxCharToStringLength;
- }
-
- Append(new string(value, index, currentCount));
- index += currentCount;
- count -= currentCount;
- }
- }
-
- ///
- /// Appends a to the collection.
- ///
- /// The to be appended.
- public void Append([NotNull] IHtmlContent htmlContent)
- {
- Entries.Add(htmlContent);
- }
-
- ///
- /// Removes all the entries from the collection.
- ///
- public void Clear()
- {
- Entries.Clear();
- }
-
- ///
- public void WriteTo([NotNull] TextWriter writer, [NotNull] IHtmlEncoder encoder)
- {
- foreach (var entry in Entries)
- {
- var entryAsString = entry as string;
- if (entryAsString != null)
- {
- writer.Write(entryAsString);
- }
- else
- {
- // Only string, IHtmlContent values can be added to the buffer.
- ((IHtmlContent)entry).WriteTo(writer, encoder);
- }
- }
- }
-
- ///
- public override string ToString()
- {
- using (var writer = new StringWriter())
- {
- WriteTo(writer, new HtmlEncoder());
- return writer.ToString();
- }
- }
- }
-}
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultDisplayTemplates.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultDisplayTemplates.cs
index 7c16f0f8b1..ac27ae1ee9 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultDisplayTemplates.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultDisplayTemplates.cs
@@ -6,17 +6,18 @@ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
-using System.Text;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering.Internal;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.DependencyInjection;
+using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
public static class DefaultDisplayTemplates
{
- public static string BooleanTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent BooleanTemplate(IHtmlHelper htmlHelper)
{
bool? value = null;
if (htmlHelper.ViewData.Model != null)
@@ -29,9 +30,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
BooleanTemplateCheckbox(value ?? false, htmlHelper);
}
- private static string BooleanTemplateCheckbox(bool value, IHtmlHelper htmlHelper)
+ private static IHtmlContent BooleanTemplateCheckbox(bool value, IHtmlHelper htmlHelper)
{
- var inputTag = new TagBuilder("input", htmlHelper.HtmlEncoder);
+ var inputTag = new TagBuilder("input");
inputTag.AddCssClass("check-box");
inputTag.Attributes["disabled"] = "disabled";
inputTag.Attributes["type"] = "checkbox";
@@ -40,28 +41,28 @@ namespace Microsoft.AspNet.Mvc.Rendering
inputTag.Attributes["checked"] = "checked";
}
- return inputTag.ToString(TagRenderMode.SelfClosing);
+ return inputTag.ToHtmlContent(TagRenderMode.SelfClosing);
}
- private static string BooleanTemplateDropDownList(IHtmlHelper htmlHelper, bool? value)
+ private static IHtmlContent BooleanTemplateDropDownList(IHtmlHelper htmlHelper, bool? value)
{
- var selectTag = new TagBuilder("select", htmlHelper.HtmlEncoder);
+ var selectTag = new TagBuilder("select");
selectTag.AddCssClass("list-box");
selectTag.AddCssClass("tri-state");
selectTag.Attributes["disabled"] = "disabled";
- var builder = new StringBuilder();
- builder.Append(selectTag.ToString(TagRenderMode.StartTag));
+ var content = new BufferedHtmlContent();
+ content.Append(selectTag.ToHtmlContent(TagRenderMode.StartTag));
foreach (var item in TriStateValues(value))
{
- var encodedText = htmlHelper.Encode(item.Text);
- var option = DefaultHtmlGenerator.GenerateOption(item, encodedText, htmlHelper.HtmlEncoder);
- builder.Append(option);
+ content.Append(
+ DefaultHtmlGenerator.GenerateOption(item, item.Text)
+ .ToHtmlContent(TagRenderMode.Normal));
}
- builder.Append(selectTag.ToString(TagRenderMode.EndTag));
- return builder.ToString();
+ content.Append(selectTag.ToHtmlContent(TagRenderMode.EndTag));
+ return content;
}
// Will soon need to be shared with the default editor templates implementations.
@@ -90,12 +91,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
};
}
- public static string CollectionTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent CollectionTemplate(IHtmlHelper htmlHelper)
{
var model = htmlHelper.ViewData.Model;
if (model == null)
{
- return string.Empty;
+ return HtmlString.Empty;
}
var collection = model as IEnumerable;
@@ -125,7 +126,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
var fieldNameBase = oldPrefix;
- var result = new StringBuilder();
+ var result = new BufferedHtmlContent();
var viewEngine = serviceProvider.GetRequiredService();
var index = 0;
@@ -153,12 +154,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
templateName: null,
readOnly: true,
additionalViewData: null);
-
- var output = templateBuilder.Build();
- result.Append(output);
+ result.Append(templateBuilder.Build());
}
- return result.ToString();
+ return result;
}
finally
{
@@ -166,7 +165,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
}
- public static string DecimalTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent DecimalTemplate(IHtmlHelper htmlHelper)
{
if (htmlHelper.ViewData.TemplateInfo.FormattedModelValue == htmlHelper.ViewData.Model)
{
@@ -177,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return StringTemplate(htmlHelper);
}
- public static string EmailAddressTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent EmailAddressTemplate(IHtmlHelper htmlHelper)
{
var uriString = "mailto:" + ((htmlHelper.ViewData.Model == null) ?
string.Empty :
@@ -189,31 +188,31 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HyperlinkTemplate(uriString, linkedText, htmlHelper);
}
- public static string HiddenInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent HiddenInputTemplate(IHtmlHelper htmlHelper)
{
if (htmlHelper.ViewData.ModelMetadata.HideSurroundingHtml)
{
- return string.Empty;
+ return HtmlString.Empty;
}
return StringTemplate(htmlHelper);
}
- public static string HtmlTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent HtmlTemplate(IHtmlHelper htmlHelper)
{
- return htmlHelper.ViewData.TemplateInfo.FormattedModelValue.ToString();
+ return new HtmlString(htmlHelper.ViewData.TemplateInfo.FormattedModelValue.ToString());
}
- public static string ObjectTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent ObjectTemplate(IHtmlHelper htmlHelper)
{
var viewData = htmlHelper.ViewData;
var templateInfo = viewData.TemplateInfo;
var modelExplorer = viewData.ModelExplorer;
- var builder = new StringBuilder();
+ var content = new BufferedHtmlContent();
if (modelExplorer.Model == null)
{
- return modelExplorer.Metadata.NullDisplayText;
+ return new HtmlString(modelExplorer.Metadata.NullDisplayText);
}
if (templateInfo.TemplateDepth > 1)
@@ -224,7 +223,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
text = htmlHelper.Encode(text);
}
- return text;
+ return new HtmlString(text);
}
var serviceProvider = htmlHelper.ViewContext.HttpContext.RequestServices;
@@ -238,7 +237,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
continue;
}
- var divTag = new TagBuilder("div", htmlHelper.HtmlEncoder);
+ var divTag = new TagBuilder("div");
if (!propertyMetadata.HideSurroundingHtml)
{
@@ -247,14 +246,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
{
divTag.SetInnerText(label);
divTag.AddCssClass("display-label");
- builder.AppendLine(divTag.ToString(TagRenderMode.Normal));
+ content.AppendLine(divTag.ToHtmlContent(TagRenderMode.Normal));
// Reset divTag for reuse.
divTag.Attributes.Clear();
}
divTag.AddCssClass("display-field");
- builder.Append(divTag.ToString(TagRenderMode.StartTag));
+ content.Append(divTag.ToHtmlContent(TagRenderMode.StartTag));
}
var templateBuilder = new TemplateBuilder(
@@ -267,15 +266,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
readOnly: true,
additionalViewData: null);
- builder.Append(templateBuilder.Build());
+ content.Append(templateBuilder.Build());
if (!propertyMetadata.HideSurroundingHtml)
{
- builder.AppendLine(divTag.ToString(TagRenderMode.EndTag));
+ content.AppendLine(divTag.ToHtmlContent(TagRenderMode.EndTag));
}
}
- return builder.ToString();
+ return content;
}
private static bool ShouldShow(ModelExplorer modelExplorer, TemplateInfo templateInfo)
@@ -286,12 +285,18 @@ namespace Microsoft.AspNet.Mvc.Rendering
!templateInfo.Visited(modelExplorer);
}
- public static string StringTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent StringTemplate(IHtmlHelper htmlHelper)
{
- return htmlHelper.Encode(htmlHelper.ViewData.TemplateInfo.FormattedModelValue);
+ var value = htmlHelper.ViewData.TemplateInfo.FormattedModelValue;
+ if (value == null)
+ {
+ return HtmlString.Empty;
+ }
+
+ return new StringHtmlContent(value.ToString());
}
- public static string UrlTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent UrlTemplate(IHtmlHelper htmlHelper)
{
var uriString = (htmlHelper.ViewData.Model == null) ? string.Empty : htmlHelper.ViewData.Model.ToString();
var linkedText = (htmlHelper.ViewData.TemplateInfo.FormattedModelValue == null) ?
@@ -302,13 +307,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
// Neither uriString nor linkedText need be encoded prior to calling this method.
- private static string HyperlinkTemplate(string uriString, string linkedText, IHtmlHelper htmlHelper)
+ private static IHtmlContent HyperlinkTemplate(string uriString, string linkedText, IHtmlHelper htmlHelper)
{
- var hyperlinkTag = new TagBuilder("a", htmlHelper.HtmlEncoder);
+ var hyperlinkTag = new TagBuilder("a");
hyperlinkTag.MergeAttribute("href", uriString);
hyperlinkTag.SetInnerText(linkedText);
- return hyperlinkTag.ToString(TagRenderMode.Normal);
+ return hyperlinkTag.ToHtmlContent(TagRenderMode.Normal);
}
}
}
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultEditorTemplates.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultEditorTemplates.cs
index b75db3a130..a2c7b60c6d 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultEditorTemplates.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultEditorTemplates.cs
@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Text;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering.Internal;
using Microsoft.AspNet.Mvc.ViewFeatures;
@@ -19,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
{
private const string HtmlAttributeKey = "htmlAttributes";
- public static string BooleanTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent BooleanTemplate(IHtmlHelper htmlHelper)
{
bool? value = null;
if (htmlHelper.ViewData.Model != null)
@@ -32,32 +33,30 @@ namespace Microsoft.AspNet.Mvc.Rendering
BooleanTemplateCheckbox(htmlHelper, value ?? false);
}
- private static string BooleanTemplateCheckbox(IHtmlHelper htmlHelper, bool value)
+ private static IHtmlContent BooleanTemplateCheckbox(IHtmlHelper htmlHelper, bool value)
{
return htmlHelper.CheckBox(
expression: null,
isChecked: value,
- htmlAttributes: CreateHtmlAttributes(htmlHelper, "check-box"))
- .ToString();
+ htmlAttributes: CreateHtmlAttributes(htmlHelper, "check-box"));
}
- private static string BooleanTemplateDropDownList(IHtmlHelper htmlHelper, bool? value)
+ private static IHtmlContent BooleanTemplateDropDownList(IHtmlHelper htmlHelper, bool? value)
{
return htmlHelper.DropDownList(
expression: null,
selectList: DefaultDisplayTemplates.TriStateValues(value),
optionLabel: null,
- htmlAttributes: CreateHtmlAttributes(htmlHelper, "list-box tri-state"))
- .ToString();
+ htmlAttributes: CreateHtmlAttributes(htmlHelper, "list-box tri-state"));
}
- public static string CollectionTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent CollectionTemplate(IHtmlHelper htmlHelper)
{
var viewData = htmlHelper.ViewData;
var model = viewData.Model;
if (model == null)
{
- return string.Empty;
+ return HtmlString.Empty;
}
var collection = model as IEnumerable;
@@ -87,7 +86,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
viewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
var fieldNameBase = oldPrefix;
- var result = new StringBuilder();
+ var result = new BufferedHtmlContent();
var viewEngine = serviceProvider.GetRequiredService();
var index = 0;
@@ -115,12 +114,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
templateName: null,
readOnly: false,
additionalViewData: null);
-
- var output = templateBuilder.Build();
- result.Append(output);
+ result.Append(templateBuilder.Build());
}
- return result.ToString();
+ return result;
}
finally
{
@@ -128,7 +125,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
}
- public static string DecimalTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent DecimalTemplate(IHtmlHelper htmlHelper)
{
if (htmlHelper.ViewData.TemplateInfo.FormattedModelValue == htmlHelper.ViewData.Model)
{
@@ -139,19 +136,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
return StringTemplate(htmlHelper);
}
- public static string HiddenInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent HiddenInputTemplate(IHtmlHelper htmlHelper)
{
var viewData = htmlHelper.ViewData;
var model = viewData.Model;
- string result;
- if (viewData.ModelMetadata.HideSurroundingHtml)
+ var result = new BufferedHtmlContent();
+ if (!viewData.ModelMetadata.HideSurroundingHtml)
{
- result = string.Empty;
- }
- else
- {
- result = DefaultDisplayTemplates.StringTemplate(htmlHelper);
+ result.Append(DefaultDisplayTemplates.StringTemplate(htmlHelper));
}
// Special-case opaque values and arbitrary binary data.
@@ -163,7 +156,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var htmlAttributesObject = viewData[HtmlAttributeKey];
var hiddenResult = htmlHelper.Hidden(expression: null, value: model, htmlAttributes: htmlAttributesObject);
- result += hiddenResult.ToString();
+ result.Append(hiddenResult);
return result;
}
@@ -219,43 +212,42 @@ namespace Microsoft.AspNet.Mvc.Rendering
return htmlAttributes;
}
- public static string MultilineTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent MultilineTemplate(IHtmlHelper htmlHelper)
{
- var htmlString = htmlHelper.TextArea(
+ return htmlHelper.TextArea(
expression: string.Empty,
value: htmlHelper.ViewContext.ViewData.TemplateInfo.FormattedModelValue.ToString(),
rows: 0,
columns: 0,
htmlAttributes: CreateHtmlAttributes(htmlHelper, "text-box multi-line"));
- return htmlString.ToString();
}
- public static string ObjectTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent ObjectTemplate(IHtmlHelper htmlHelper)
{
var viewData = htmlHelper.ViewData;
var templateInfo = viewData.TemplateInfo;
var modelExplorer = viewData.ModelExplorer;
- var builder = new StringBuilder();
if (templateInfo.TemplateDepth > 1)
{
if (modelExplorer.Model == null)
{
- return modelExplorer.Metadata.NullDisplayText;
+ return new HtmlString(modelExplorer.Metadata.NullDisplayText);
}
var text = modelExplorer.GetSimpleDisplayText();
if (modelExplorer.Metadata.HtmlEncode)
{
- text = htmlHelper.Encode(text);
+ return new StringHtmlContent(text);
}
- return text;
+ return new HtmlString(text);
}
var serviceProvider = htmlHelper.ViewContext.HttpContext.RequestServices;
var viewEngine = serviceProvider.GetRequiredService();
+ var content = new BufferedHtmlContent();
foreach (var propertyExplorer in modelExplorer.Properties)
{
var propertyMetadata = propertyExplorer.Metadata;
@@ -264,27 +256,26 @@ namespace Microsoft.AspNet.Mvc.Rendering
continue;
}
- var divTag = new TagBuilder("div", htmlHelper.HtmlEncoder);
+ var divTag = new TagBuilder("div");
if (!propertyMetadata.HideSurroundingHtml)
{
var label = htmlHelper.Label(
propertyMetadata.PropertyName,
labelText: null,
- htmlAttributes: null)
- .ToString();
- if (!string.IsNullOrEmpty(label))
+ htmlAttributes: null);
+ if (!string.IsNullOrEmpty(label.ToString()))
{
divTag.AddCssClass("editor-label");
divTag.InnerHtml = label; // already escaped
- builder.AppendLine(divTag.ToString(TagRenderMode.Normal));
+ content.AppendLine(divTag.ToHtmlContent(TagRenderMode.Normal));
// Reset divTag for reuse.
divTag.Attributes.Clear();
}
divTag.AddCssClass("editor-field");
- builder.Append(divTag.ToString(TagRenderMode.StartTag));
+ content.Append(divTag.ToHtmlContent(TagRenderMode.StartTag));
}
var templateBuilder = new TemplateBuilder(
@@ -297,31 +288,30 @@ namespace Microsoft.AspNet.Mvc.Rendering
readOnly: false,
additionalViewData: null);
- builder.Append(templateBuilder.Build());
+ content.Append(templateBuilder.Build());
if (!propertyMetadata.HideSurroundingHtml)
{
- builder.Append(" ");
- builder.Append(htmlHelper.ValidationMessage(
+ content.Append(" ");
+ content.Append(htmlHelper.ValidationMessage(
propertyMetadata.PropertyName,
message: null,
htmlAttributes: null,
tag: null));
- builder.AppendLine(divTag.ToString(TagRenderMode.EndTag));
+ content.AppendLine(divTag.ToHtmlContent(TagRenderMode.EndTag));
}
}
- return builder.ToString();
+ return content;
}
- public static string PasswordTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent PasswordTemplate(IHtmlHelper htmlHelper)
{
return htmlHelper.Password(
expression: null,
value: htmlHelper.ViewData.TemplateInfo.FormattedModelValue,
- htmlAttributes: CreateHtmlAttributes(htmlHelper, "text-box single-line password"))
- .ToString();
+ htmlAttributes: CreateHtmlAttributes(htmlHelper, "text-box single-line password"));
}
private static bool ShouldShow(ModelExplorer modelExplorer, TemplateInfo templateInfo)
@@ -332,61 +322,61 @@ namespace Microsoft.AspNet.Mvc.Rendering
!templateInfo.Visited(modelExplorer);
}
- public static string StringTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent StringTemplate(IHtmlHelper htmlHelper)
{
return GenerateTextBox(htmlHelper);
}
- public static string PhoneNumberInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent PhoneNumberInputTemplate(IHtmlHelper htmlHelper)
{
return GenerateTextBox(htmlHelper, inputType: "tel");
}
- public static string UrlInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent UrlInputTemplate(IHtmlHelper htmlHelper)
{
return GenerateTextBox(htmlHelper, inputType: "url");
}
- public static string EmailAddressInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent EmailAddressInputTemplate(IHtmlHelper htmlHelper)
{
return GenerateTextBox(htmlHelper, inputType: "email");
}
- public static string DateTimeInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent DateTimeInputTemplate(IHtmlHelper htmlHelper)
{
ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:yyyy-MM-ddTHH:mm:ss.fffK}");
return GenerateTextBox(htmlHelper, inputType: "datetime");
}
- public static string DateTimeLocalInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent DateTimeLocalInputTemplate(IHtmlHelper htmlHelper)
{
ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:yyyy-MM-ddTHH:mm:ss.fff}");
return GenerateTextBox(htmlHelper, inputType: "datetime-local");
}
- public static string DateInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent DateInputTemplate(IHtmlHelper htmlHelper)
{
ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:yyyy-MM-dd}");
return GenerateTextBox(htmlHelper, inputType: "date");
}
- public static string TimeInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent TimeInputTemplate(IHtmlHelper htmlHelper)
{
ApplyRfc3339DateFormattingIfNeeded(htmlHelper, "{0:HH:mm:ss.fff}");
return GenerateTextBox(htmlHelper, inputType: "time");
}
- public static string NumberInputTemplate(IHtmlHelper htmlHelper)
+ public static IHtmlContent NumberInputTemplate(IHtmlHelper htmlHelper)
{
return GenerateTextBox(htmlHelper, inputType: "number");
}
- public static string FileInputTemplate([NotNull] IHtmlHelper htmlHelper)
+ public static IHtmlContent FileInputTemplate([NotNull] IHtmlHelper htmlHelper)
{
return GenerateTextBox(htmlHelper, inputType: "file");
}
- public static string FileCollectionInputTemplate([NotNull] IHtmlHelper htmlHelper)
+ public static IHtmlContent FileCollectionInputTemplate([NotNull] IHtmlHelper htmlHelper)
{
var htmlAttributes =
CreateHtmlAttributes(htmlHelper, className: "text-box single-line", inputType: "file");
@@ -416,12 +406,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
}
- private static string GenerateTextBox(IHtmlHelper htmlHelper, string inputType = null)
+ private static IHtmlContent GenerateTextBox(IHtmlHelper htmlHelper, string inputType = null)
{
return GenerateTextBox(htmlHelper, inputType, htmlHelper.ViewData.TemplateInfo.FormattedModelValue);
}
- private static string GenerateTextBox(IHtmlHelper htmlHelper, string inputType, object value)
+ private static IHtmlContent GenerateTextBox(IHtmlHelper htmlHelper, string inputType, object value)
{
var htmlAttributes =
CreateHtmlAttributes(htmlHelper, className: "text-box single-line", inputType: inputType);
@@ -429,14 +419,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
return GenerateTextBox(htmlHelper, value, htmlAttributes);
}
- private static string GenerateTextBox(IHtmlHelper htmlHelper, object value, object htmlAttributes)
+ private static IHtmlContent GenerateTextBox(IHtmlHelper htmlHelper, object value, object htmlAttributes)
{
return htmlHelper.TextBox(
current: null,
value: value,
format: null,
- htmlAttributes: htmlAttributes)
- .ToString();
+ htmlAttributes: htmlAttributes);
}
}
}
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultHtmlGenerator.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultHtmlGenerator.cs
index 9573dce101..9fd4cf2698 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultHtmlGenerator.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/DefaultHtmlGenerator.cs
@@ -10,6 +10,7 @@ using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.AspNet.Antiforgery;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.Rendering.Expressions;
@@ -96,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public virtual HtmlString GenerateAntiforgery([NotNull] ViewContext viewContext)
+ public virtual IHtmlContent GenerateAntiforgery([NotNull] ViewContext viewContext)
{
var tag = _antiforgery.GetHtml(viewContext.HttpContext);
return new HtmlString(tag);
@@ -153,7 +154,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
ModelExplorer modelExplorer,
string expression)
{
- var tagBuilder = new TagBuilder("input", _htmlEncoder);
+ var tagBuilder = new TagBuilder("input");
tagBuilder.MergeAttribute("type", GetInputTypeString(InputType.Hidden));
tagBuilder.MergeAttribute("value", "false");
@@ -266,7 +267,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return null;
}
- var tagBuilder = new TagBuilder("label", _htmlEncoder);
+ var tagBuilder = new TagBuilder("label");
var idString =
TagBuilder.CreateSanitizedId(GetFullHtmlFieldName(viewContext, expression), IdAttributeDotReplacement);
tagBuilder.Attributes.Add("for", idString);
@@ -439,9 +440,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
// Convert each ListItem to an tag and wrap them with if requested.
var listItemBuilder = GenerateGroupsAndOptions(optionLabel, selectList);
- var tagBuilder = new TagBuilder("select", _htmlEncoder)
+ var tagBuilder = new TagBuilder("select")
{
- InnerHtml = listItemBuilder.ToString()
+ InnerHtml = listItemBuilder
};
tagBuilder.MergeAttributes(GetHtmlAttributeDictionaryOrNull(htmlAttributes));
tagBuilder.MergeAttribute("name", fullName, true /* replaceExisting */);
@@ -513,7 +514,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
value = modelExplorer.Model.ToString();
}
- var tagBuilder = new TagBuilder("textarea", _htmlEncoder);
+ var tagBuilder = new TagBuilder("textarea");
tagBuilder.GenerateId(fullName, IdAttributeDotReplacement);
tagBuilder.MergeAttributes(GetHtmlAttributeDictionaryOrNull(htmlAttributes), true);
if (rows > 0)
@@ -537,7 +538,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
// The first newline is always trimmed when a TextArea is rendered, so we add an extra one
// in case the value being rendered is something like "\r\nHello".
- tagBuilder.InnerHtml = Environment.NewLine + _htmlEncoder.HtmlEncode(value);
+ var innerContent = new BufferedHtmlContent();
+ innerContent.Append(Environment.NewLine);
+ innerContent.Append(new StringHtmlContent(value));
+ tagBuilder.InnerHtml = innerContent;
return tagBuilder;
}
@@ -614,7 +618,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
{
tag = viewContext.ValidationMessageElement;
}
- var tagBuilder = new TagBuilder(tag, _htmlEncoder);
+ var tagBuilder = new TagBuilder(tag);
tagBuilder.MergeAttributes(GetHtmlAttributeDictionaryOrNull(htmlAttributes));
// Only the style of the span is changed according to the errors if message is null or empty.
@@ -660,16 +664,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
return null;
}
- string wrappedMessage;
+ var wrappedMessage = new BufferedHtmlContent();
if (!string.IsNullOrEmpty(message))
{
if (string.IsNullOrEmpty(headerTag))
{
headerTag = viewContext.ValidationSummaryMessageElement;
}
- var messageTag = new TagBuilder(headerTag, _htmlEncoder);
+ var messageTag = new TagBuilder(headerTag);
messageTag.SetInnerText(message);
- wrappedMessage = messageTag.ToString(TagRenderMode.Normal) + Environment.NewLine;
+ wrappedMessage.AppendLine(messageTag.ToHtmlContent(TagRenderMode.Normal));
}
else
{
@@ -678,7 +682,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
// If excludePropertyErrors is true, describe any validation issue with the current model in a single item.
// Otherwise, list individual property errors.
- var htmlSummary = new StringBuilder();
+ var htmlSummary = new BufferedHtmlContent();
+ var isHtmlSummaryModified = false;
var modelStates = ValidationHelpers.GetModelStateList(viewContext.ViewData, excludePropertyErrors);
foreach (var modelState in modelStates)
@@ -689,24 +694,25 @@ namespace Microsoft.AspNet.Mvc.Rendering
if (!string.IsNullOrEmpty(errorText))
{
- var listItem = new TagBuilder("li", _htmlEncoder);
+ var listItem = new TagBuilder("li");
listItem.SetInnerText(errorText);
- htmlSummary.AppendLine(listItem.ToString(TagRenderMode.Normal));
+ htmlSummary.AppendLine(listItem.ToHtmlContent(TagRenderMode.Normal));
+ isHtmlSummaryModified = true;
}
}
}
- if (htmlSummary.Length == 0)
+ if (!isHtmlSummaryModified)
{
htmlSummary.AppendLine(HiddenListItem);
}
- var unorderedList = new TagBuilder("ul", _htmlEncoder)
+ var unorderedList = new TagBuilder("ul")
{
- InnerHtml = htmlSummary.ToString()
+ InnerHtml = htmlSummary
};
- var tagBuilder = new TagBuilder("div", _htmlEncoder);
+ var tagBuilder = new TagBuilder("div");
tagBuilder.MergeAttributes(GetHtmlAttributeDictionaryOrNull(htmlAttributes));
if (viewContext.ViewData.ModelState.IsValid)
@@ -718,7 +724,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
tagBuilder.AddCssClass(HtmlHelper.ValidationSummaryCssClassName);
}
- tagBuilder.InnerHtml = wrappedMessage + unorderedList.ToString(TagRenderMode.Normal);
+ var innerContent = new BufferedHtmlContent();
+ innerContent.Append(wrappedMessage);
+ innerContent.Append(unorderedList.ToHtmlContent(TagRenderMode.Normal));
+ tagBuilder.InnerHtml = innerContent;
if (formContext != null && !excludePropertyErrors)
{
@@ -898,12 +907,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// Not used directly in HtmlHelper. Exposed for use in DefaultDisplayTemplates.
///
- internal static TagBuilder GenerateOption(SelectListItem item, string encodedText, IHtmlEncoder htmlEncoder)
+ internal static TagBuilder GenerateOption(SelectListItem item, string text)
{
- var tagBuilder = new TagBuilder("option", htmlEncoder)
- {
- InnerHtml = encodedText,
- };
+ var tagBuilder = new TagBuilder("option");
+ tagBuilder.SetInnerText(text);
if (item.Value != null)
{
@@ -959,7 +966,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
string method,
object htmlAttributes)
{
- var tagBuilder = new TagBuilder("form", _htmlEncoder);
+ var tagBuilder = new TagBuilder("form");
tagBuilder.MergeAttributes(GetHtmlAttributeDictionaryOrNull(htmlAttributes));
// action is implicitly generated from other parameters, so htmlAttributes take precedence.
@@ -1007,7 +1014,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
nameof(expression));
}
- var tagBuilder = new TagBuilder("input", _htmlEncoder);
+ var tagBuilder = new TagBuilder("input");
tagBuilder.MergeAttributes(htmlAttributes);
tagBuilder.MergeAttribute("type", GetInputTypeString(inputType));
tagBuilder.MergeAttribute("name", fullName, replaceExisting: true);
@@ -1108,9 +1115,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
[NotNull] string url,
object htmlAttributes)
{
- var tagBuilder = new TagBuilder("a", _htmlEncoder)
+ var tagBuilder = new TagBuilder("a")
{
- InnerHtml = _htmlEncoder.HtmlEncode(linkText),
+ InnerHtml = new StringHtmlContent(linkText),
};
tagBuilder.MergeAttributes(GetHtmlAttributeDictionaryOrNull(htmlAttributes));
@@ -1272,9 +1279,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
return newSelectList;
}
- private StringBuilder GenerateGroupsAndOptions(string optionLabel, IEnumerable selectList)
+ private IHtmlContent GenerateGroupsAndOptions(string optionLabel, IEnumerable selectList)
{
- var listItemBuilder = new StringBuilder();
+ var listItemBuilder = new BufferedHtmlContent();
// Make optionLabel the first item that gets rendered.
if (optionLabel != null)
@@ -1300,7 +1307,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
TagBuilder groupBuilder = null;
if (optGroup != null)
{
- groupBuilder = new TagBuilder("optgroup", _htmlEncoder);
+ groupBuilder = new TagBuilder("optgroup");
if (optGroup.Name != null)
{
groupBuilder.MergeAttribute("label", optGroup.Name);
@@ -1311,7 +1318,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
groupBuilder.MergeAttribute("disabled", "disabled");
}
- listItemBuilder.AppendLine(groupBuilder.ToString(TagRenderMode.StartTag));
+ listItemBuilder.AppendLine(groupBuilder.ToHtmlContent(TagRenderMode.StartTag));
}
foreach (var item in group)
@@ -1321,19 +1328,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
if (optGroup != null)
{
- listItemBuilder.AppendLine(groupBuilder.ToString(TagRenderMode.EndTag));
+ listItemBuilder.AppendLine(groupBuilder.ToHtmlContent(TagRenderMode.EndTag));
}
}
return listItemBuilder;
}
- private string GenerateOption(SelectListItem item)
+ private IHtmlContent GenerateOption(SelectListItem item)
{
- var encodedText = Encode(item.Text);
- var tagBuilder = GenerateOption(item, encodedText, _htmlEncoder);
-
- return tagBuilder.ToString(TagRenderMode.Normal);
+ var tagBuilder = GenerateOption(item, item.Text);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
}
}
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/HtmlHelper.cs
index 4c9a368a89..98b7bbfced 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/HtmlHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/HtmlHelper.cs
@@ -32,6 +32,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
private readonly IHtmlGenerator _htmlGenerator;
private readonly ICompositeViewEngine _viewEngine;
+ private readonly IHtmlEncoder _htmlEncoder;
private ViewContext _viewContext;
@@ -48,8 +49,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
{
_viewEngine = viewEngine;
_htmlGenerator = htmlGenerator;
+ _htmlEncoder = htmlEncoder;
MetadataProvider = metadataProvider;
- HtmlEncoder = htmlEncoder;
UrlEncoder = urlEncoder;
JavaScriptStringEncoder = javaScriptStringEncoder;
}
@@ -121,9 +122,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
}
- ///
- public IHtmlEncoder HtmlEncoder { get; }
-
///
public IUrlEncoder UrlEncoder { get; }
@@ -192,7 +190,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString ActionLink(
+ public IHtmlContent ActionLink(
[NotNull] string linkText,
string actionName,
string controllerName,
@@ -216,11 +214,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.Normal);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
///
- public HtmlString AntiForgeryToken()
+ public IHtmlContent AntiForgeryToken()
{
var html = _htmlGenerator.GenerateAntiforgery(ViewContext);
return html ?? HtmlString.Empty;
@@ -251,7 +249,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString CheckBox(string expression, bool? isChecked, object htmlAttributes)
+ public IHtmlContent CheckBox(string expression, bool? isChecked, object htmlAttributes)
{
return GenerateCheckBox(
modelExplorer: null,
@@ -285,7 +283,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString Display(string expression,
+ public IHtmlContent Display(string expression,
string templateName,
string htmlFieldName,
object additionalViewData)
@@ -313,7 +311,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString DropDownList(
+ public IHtmlContent DropDownList(
string expression,
IEnumerable selectList,
string optionLabel,
@@ -328,7 +326,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString Editor(
+ public IHtmlContent Editor(
string expression,
string templateName,
string htmlFieldName,
@@ -377,7 +375,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString Hidden(string expression, object value, object htmlAttributes)
+ public IHtmlContent Hidden(string expression, object value, object htmlAttributes)
{
return GenerateHidden(
modelExplorer: null,
@@ -394,7 +392,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString Label(string expression, string labelText, object htmlAttributes)
+ public IHtmlContent Label(string expression, string labelText, object htmlAttributes)
{
var modelExplorer = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
return GenerateLabel(
@@ -405,7 +403,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString ListBox(string expression, IEnumerable selectList, object htmlAttributes)
+ public IHtmlContent ListBox(string expression, IEnumerable selectList, object htmlAttributes)
{
return GenerateListBox(
modelExplorer: null,
@@ -439,7 +437,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return RenderPartialCoreAsync(partialViewName, model, viewData, ViewContext.Writer);
}
- protected virtual HtmlString GenerateDisplay(ModelExplorer modelExplorer,
+ protected virtual IHtmlContent GenerateDisplay(ModelExplorer modelExplorer,
string htmlFieldName,
string templateName,
object additionalViewData)
@@ -453,9 +451,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
readOnly: true,
additionalViewData: additionalViewData);
- var templateResult = templateBuilder.Build();
-
- return new HtmlString(templateResult);
+ return templateBuilder.Build();
}
protected virtual async Task RenderPartialCoreAsync([NotNull] string partialViewName,
@@ -491,7 +487,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString Password(string expression, object value, object htmlAttributes)
+ public IHtmlContent Password(string expression, object value, object htmlAttributes)
{
return GeneratePassword(
modelExplorer: null,
@@ -501,7 +497,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString RadioButton(string expression, object value, bool? isChecked, object htmlAttributes)
+ public IHtmlContent RadioButton(string expression, object value, bool? isChecked, object htmlAttributes)
{
return GenerateRadioButton(
modelExplorer: null,
@@ -512,19 +508,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString Raw(string value)
+ public IHtmlContent Raw(string value)
{
return new HtmlString(value);
}
///
- public HtmlString Raw(object value)
+ public IHtmlContent Raw(object value)
{
return new HtmlString(value == null ? null : value.ToString());
}
///
- public HtmlString RouteLink(
+ public IHtmlContent RouteLink(
[NotNull] string linkText,
string routeName,
string protocol,
@@ -546,17 +542,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.Normal);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
///
- public HtmlString ValidationMessage(string expression, string message, object htmlAttributes, string tag)
+ public IHtmlContent ValidationMessage(string expression, string message, object htmlAttributes, string tag)
{
return GenerateValidationMessage(expression, message, htmlAttributes, tag);
}
///
- public HtmlString ValidationSummary(
+ public IHtmlContent ValidationSummary(
bool excludePropertyErrors,
string message,
object htmlAttributes,
@@ -584,7 +580,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString TextArea(string expression, string value, int rows, int columns, object htmlAttributes)
+ public IHtmlContent TextArea(string expression, string value, int rows, int columns, object htmlAttributes)
{
var modelExplorer = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
if (value != null)
@@ -606,7 +602,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString TextBox(string expression, object value, string format, object htmlAttributes)
+ public IHtmlContent TextBox(string expression, object value, string format, object htmlAttributes)
{
return GenerateTextBox(modelExplorer: null, expression: expression, value: value, format: format,
htmlAttributes: htmlAttributes);
@@ -628,7 +624,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return new MvcForm(ViewContext);
}
- protected virtual HtmlString GenerateCheckBox(
+ protected virtual IHtmlContent GenerateCheckBox(
ModelExplorer modelExplorer,
string expression,
bool? isChecked,
@@ -647,9 +643,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- var elements = checkbox.ToString(TagRenderMode.SelfClosing) + hidden.ToString(TagRenderMode.SelfClosing);
+ var elements = new BufferedHtmlContent();
+ elements.Append(checkbox.ToHtmlContent(TagRenderMode.SelfClosing));
+ elements.Append(hidden.ToHtmlContent(TagRenderMode.SelfClosing));
- return new HtmlString(elements);
+ return elements;
}
protected virtual string GenerateDisplayName([NotNull] ModelExplorer modelExplorer, string expression)
@@ -672,7 +670,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return modelExplorer.GetSimpleDisplayText() ?? string.Empty;
}
- protected HtmlString GenerateDropDown(
+ protected IHtmlContent GenerateDropDown(
ModelExplorer modelExplorer,
string expression,
IEnumerable selectList,
@@ -692,10 +690,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.Normal);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
- protected virtual HtmlString GenerateEditor(
+ protected virtual IHtmlContent GenerateEditor(
ModelExplorer modelExplorer,
string htmlFieldName,
string templateName,
@@ -711,9 +709,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
readOnly: false,
additionalViewData: additionalViewData);
- var templateResult = templateBuilder.Build();
-
- return new HtmlString(templateResult);
+ return templateBuilder.Build();
}
///
@@ -755,7 +751,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes);
if (tagBuilder != null)
{
- ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));
+ tagBuilder.ToHtmlContent(TagRenderMode.StartTag).WriteTo(ViewContext.Writer, _htmlEncoder);
}
return CreateForm();
@@ -797,13 +793,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes);
if (tagBuilder != null)
{
- ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));
+ tagBuilder.ToHtmlContent(TagRenderMode.StartTag).WriteTo(ViewContext.Writer, _htmlEncoder);
}
return CreateForm();
}
- protected virtual HtmlString GenerateHidden(
+ protected virtual IHtmlContent GenerateHidden(
ModelExplorer modelExplorer,
string expression,
object value,
@@ -823,7 +819,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.SelfClosing);
+ return tagBuilder.ToHtmlContent(TagRenderMode.SelfClosing);
}
protected virtual string GenerateId(string expression)
@@ -834,7 +830,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return id;
}
- protected virtual HtmlString GenerateLabel(
+ protected virtual IHtmlContent GenerateLabel(
[NotNull] ModelExplorer modelExplorer,
string expression,
string labelText,
@@ -851,10 +847,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.Normal);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
- protected HtmlString GenerateListBox(
+ protected IHtmlContent GenerateListBox(
ModelExplorer modelExplorer,
string expression,
IEnumerable selectList,
@@ -873,7 +869,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.Normal);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
protected virtual string GenerateName(string expression)
@@ -882,7 +878,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return fullName;
}
- protected virtual HtmlString GeneratePassword(
+ protected virtual IHtmlContent GeneratePassword(
ModelExplorer modelExplorer,
string expression,
object value,
@@ -899,10 +895,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.SelfClosing);
+ return tagBuilder.ToHtmlContent(TagRenderMode.SelfClosing);
}
- protected virtual HtmlString GenerateRadioButton(
+ protected virtual IHtmlContent GenerateRadioButton(
ModelExplorer modelExplorer,
string expression,
object value,
@@ -921,10 +917,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.SelfClosing);
+ return tagBuilder.ToHtmlContent(TagRenderMode.SelfClosing);
}
- protected virtual HtmlString GenerateTextArea(
+ protected virtual IHtmlContent GenerateTextArea(
ModelExplorer modelExplorer,
string expression,
int rows,
@@ -943,10 +939,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.Normal);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
- protected virtual HtmlString GenerateTextBox(
+ protected virtual IHtmlContent GenerateTextBox(
ModelExplorer modelExplorer,
string expression,
object value,
@@ -965,10 +961,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.SelfClosing);
+ return tagBuilder.ToHtmlContent(TagRenderMode.SelfClosing);
}
- protected virtual HtmlString GenerateValidationMessage(
+ protected virtual IHtmlContent GenerateValidationMessage(
string expression,
string message,
object htmlAttributes,
@@ -985,10 +981,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.Normal);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
- protected virtual HtmlString GenerateValidationSummary(
+ protected virtual IHtmlContent GenerateValidationSummary(
bool excludePropertyErrors,
string message,
object htmlAttributes,
@@ -1005,7 +1001,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
return HtmlString.Empty;
}
- return tagBuilder.ToHtmlString(TagRenderMode.Normal);
+ return tagBuilder.ToHtmlContent(TagRenderMode.Normal);
}
protected virtual string GenerateValue(string expression, object value, string format, bool useViewData)
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/HtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/HtmlHelperOfT.cs
index 942135ab99..bec37c5cdd 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/HtmlHelperOfT.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/HtmlHelperOfT.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering.Expressions;
using Microsoft.AspNet.Mvc.ViewFeatures;
@@ -56,7 +57,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString CheckBoxFor(
+ public IHtmlContent CheckBoxFor(
[NotNull] Expression> expression,
object htmlAttributes)
{
@@ -66,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString DropDownListFor(
+ public IHtmlContent DropDownListFor(
[NotNull] Expression> expression,
IEnumerable selectList,
string optionLabel,
@@ -79,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString DisplayFor(
+ public IHtmlContent DisplayFor(
[NotNull] Expression> expression,
string templateName,
string htmlFieldName,
@@ -127,7 +128,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString EditorFor(
+ public IHtmlContent EditorFor(
[NotNull] Expression> expression,
string templateName,
string htmlFieldName,
@@ -143,7 +144,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString HiddenFor(
+ public IHtmlContent HiddenFor(
[NotNull] Expression> expression,
object htmlAttributes)
{
@@ -163,7 +164,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString LabelFor(
+ public IHtmlContent LabelFor(
[NotNull] Expression> expression,
string labelText,
object htmlAttributes)
@@ -177,7 +178,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString ListBoxFor(
+ public IHtmlContent ListBoxFor(
[NotNull] Expression> expression,
IEnumerable selectList,
object htmlAttributes)
@@ -196,7 +197,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString PasswordFor(
+ public IHtmlContent PasswordFor(
[NotNull] Expression> expression,
object htmlAttributes)
{
@@ -209,7 +210,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString RadioButtonFor(
+ public IHtmlContent RadioButtonFor(
[NotNull] Expression> expression,
[NotNull] object value,
object htmlAttributes)
@@ -224,7 +225,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString TextAreaFor(
+ public IHtmlContent TextAreaFor(
[NotNull] Expression> expression,
int rows,
int columns,
@@ -235,7 +236,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString TextBoxFor(
+ public IHtmlContent TextBoxFor(
[NotNull] Expression> expression,
string format,
object htmlAttributes)
@@ -267,7 +268,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
///
- public HtmlString ValidationMessageFor(
+ public IHtmlContent ValidationMessageFor(
[NotNull] Expression> expression,
string message,
object htmlAttributes,
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/IHtmlGenerator.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/IHtmlGenerator.cs
index 4993163f01..0209f893e3 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/IHtmlGenerator.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/IHtmlGenerator.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
@@ -35,8 +36,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Genrate an <input type="hidden".../> element containing an antiforgery token.
///
/// The instance for the current scope.
- /// An instance for the <input type="hidden".../> element.
- HtmlString GenerateAntiforgery([NotNull] ViewContext viewContext);
+ /// An instance for the <input type="hidden".../> element.
+ IHtmlContent GenerateAntiforgery([NotNull] ViewContext viewContext);
///
/// Generate a <input type="checkbox".../> element.
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/TagBuilder.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/TagBuilder.cs
index d81660c0e4..08d86ae1f1 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/TagBuilder.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Html/TagBuilder.cs
@@ -6,23 +6,15 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
-using Microsoft.Framework.WebEncoders;
namespace Microsoft.AspNet.Mvc.Rendering
{
public class TagBuilder
{
- private string _innerHtml;
- private readonly IHtmlEncoder _htmlEncoder;
-
public TagBuilder(string tagName)
- : this(tagName, HtmlEncoder.Default)
- {
- }
-
- public TagBuilder(string tagName, [NotNull] IHtmlEncoder htmlEncoder)
{
if (string.IsNullOrEmpty(tagName))
{
@@ -31,16 +23,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
TagName = tagName;
Attributes = new SortedDictionary(StringComparer.OrdinalIgnoreCase);
- _htmlEncoder = htmlEncoder;
}
public IDictionary Attributes { get; private set; }
- public string InnerHtml
- {
- get { return _innerHtml ?? string.Empty; }
- set { _innerHtml = value; }
- }
+ public IHtmlContent InnerHtml { get; [param: NotNull] set; } = HtmlString.Empty;
public string TagName { get; private set; }
@@ -138,7 +125,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
}
- private void AppendAttributes(TextWriter textWriter)
+ private void AppendAttributes(BufferedHtmlContent content)
{
foreach (var attribute in Attributes)
{
@@ -149,11 +136,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
continue;
}
- textWriter.Write(' ');
- textWriter.Write(key);
- textWriter.Write("=\"");
- _htmlEncoder.HtmlEncode(attribute.Value, textWriter);
- textWriter.Write('"');
+ content.Append(" ");
+ content.Append(key);
+ content.Append("=\"");
+ content.Append(new StringHtmlContent(attribute.Value));
+ content.Append("\"");
}
}
@@ -195,56 +182,51 @@ namespace Microsoft.AspNet.Mvc.Rendering
public void SetInnerText(string innerText)
{
- InnerHtml = _htmlEncoder.HtmlEncode(innerText);
+ InnerHtml = new StringHtmlContent(innerText);
}
- public HtmlString ToHtmlString(TagRenderMode renderMode)
+ ///
+ /// Converts the to with the specified
+ /// .
+ ///
+ /// with which the
+ /// should be written.
+ /// containing the contents of the .
+ public IHtmlContent ToHtmlContent(TagRenderMode renderMode)
{
- return new HtmlString(ToString(renderMode));
- }
-
- public override string ToString()
- {
- return ToString(TagRenderMode.Normal);
- }
-
- public string ToString(TagRenderMode renderMode)
- {
- using (var stringWriter = new StringWriter())
+ var content = new BufferedHtmlContent();
+ switch (renderMode)
{
- switch (renderMode)
- {
- case TagRenderMode.StartTag:
- stringWriter.Write('<');
- stringWriter.Write(TagName);
- AppendAttributes(stringWriter);
- stringWriter.Write('>');
- break;
- case TagRenderMode.EndTag:
- stringWriter.Write("");
- stringWriter.Write(TagName);
- stringWriter.Write('>');
- break;
- case TagRenderMode.SelfClosing:
- stringWriter.Write('<');
- stringWriter.Write(TagName);
- AppendAttributes(stringWriter);
- stringWriter.Write(" />");
- break;
- default:
- stringWriter.Write('<');
- stringWriter.Write(TagName);
- AppendAttributes(stringWriter);
- stringWriter.Write('>');
- stringWriter.Write(InnerHtml);
- stringWriter.Write("");
- stringWriter.Write(TagName);
- stringWriter.Write('>');
- break;
- }
-
- return stringWriter.ToString();
+ case TagRenderMode.StartTag:
+ content.Append("<");
+ content.Append(TagName);
+ AppendAttributes(content);
+ content.Append(">");
+ break;
+ case TagRenderMode.EndTag:
+ content.Append("");
+ content.Append(TagName);
+ content.Append(">");
+ break;
+ case TagRenderMode.SelfClosing:
+ content.Append("<");
+ content.Append(TagName);
+ AppendAttributes(content);
+ content.Append(" />");
+ break;
+ default:
+ content.Append("<");
+ content.Append(TagName);
+ AppendAttributes(content);
+ content.Append(">");
+ content.Append(InnerHtml);
+ content.Append("");
+ content.Append(TagName);
+ content.Append(">");
+ break;
}
+
+ return content;
}
private static class Html401IdUtil
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayExtensions.cs
index ea2f142bc5..5653b5c55c 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperDisplayExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.Linq.Expressions;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -21,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Expression name, relative to the current model. May identify a single property or an
/// that contains the properties to display.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -36,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Display([NotNull] this IHtmlHelper htmlHelper, string expression)
+ public static IHtmlContent Display([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.Display(expression, templateName: null, htmlFieldName: null, additionalViewData: null);
}
@@ -56,7 +57,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -71,7 +72,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Display(
+ public static IHtmlContent Display(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object additionalViewData)
@@ -94,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that contains the properties to display.
///
/// The name of the template used to create the HTML markup.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -109,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Display(
+ public static IHtmlContent Display(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string templateName)
@@ -133,7 +134,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -148,7 +149,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Display(
+ public static IHtmlContent Display(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string templateName,
@@ -176,7 +177,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// A used to disambiguate the names of HTML elements that are created for
/// properties that have the same name.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -191,7 +192,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Display(
+ public static IHtmlContent Display(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string templateName,
@@ -208,7 +209,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An expression to be evaluated against the current model.
/// The type of the model.
/// The type of the result.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -219,7 +220,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayFor(
+ public static IHtmlContent DisplayFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -244,7 +245,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -255,7 +256,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayFor(
+ public static IHtmlContent DisplayFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
object additionalViewData)
@@ -277,7 +278,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The name of the template used to create the HTML markup.
/// The type of the model.
/// The type of the result.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -288,7 +289,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayFor(
+ public static IHtmlContent DisplayFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string templateName)
@@ -315,7 +316,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -326,7 +327,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayFor(
+ public static IHtmlContent DisplayFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string templateName,
@@ -353,7 +354,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -364,7 +365,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayFor(
+ public static IHtmlContent DisplayFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string templateName,
@@ -382,7 +383,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// model's .
///
/// The instance this method extends.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -393,7 +394,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayForModel([NotNull] this IHtmlHelper htmlHelper)
+ public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper)
{
return htmlHelper.Display(
expression: null,
@@ -412,7 +413,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -423,7 +424,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayForModel([NotNull] this IHtmlHelper htmlHelper, object additionalViewData)
+ public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper, object additionalViewData)
{
return htmlHelper.Display(
expression: null,
@@ -438,7 +439,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// The name of the template used to create the HTML markup.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -449,7 +450,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayForModel([NotNull] this IHtmlHelper htmlHelper, string templateName)
+ public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper, string templateName)
{
return htmlHelper.Display(
expression: null,
@@ -470,7 +471,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -481,7 +482,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayForModel(
+ public static IHtmlContent DisplayForModel(
[NotNull] this IHtmlHelper htmlHelper,
string templateName,
object additionalViewData)
@@ -504,7 +505,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// A used to disambiguate the names of HTML elements that are created for
/// properties that have the same name.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -515,7 +516,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayForModel(
+ public static IHtmlContent DisplayForModel(
[NotNull] this IHtmlHelper htmlHelper,
string templateName,
string htmlFieldName)
@@ -543,7 +544,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -554,7 +555,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString DisplayForModel(
+ public static IHtmlContent DisplayForModel(
[NotNull] this IHtmlHelper htmlHelper,
string templateName,
string htmlFieldName,
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperEditorExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperEditorExtensions.cs
index dd7fa38c5d..75450fde83 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperEditorExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperEditorExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.Linq.Expressions;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -21,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Expression name, relative to the current model. May identify a single property or an
/// that contains the properties to edit.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -36,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Editor([NotNull] this IHtmlHelper htmlHelper, string expression)
+ public static IHtmlContent Editor([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.Editor(expression, templateName: null, htmlFieldName: null, additionalViewData: null);
}
@@ -56,7 +57,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -71,7 +72,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Editor(
+ public static IHtmlContent Editor(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object additionalViewData)
@@ -94,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that contains the properties to edit.
///
/// The name of the template used to create the HTML markup.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -109,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Editor([NotNull] this IHtmlHelper htmlHelper, string expression, string templateName)
+ public static IHtmlContent Editor([NotNull] this IHtmlHelper htmlHelper, string expression, string templateName)
{
return htmlHelper.Editor(expression, templateName, htmlFieldName: null, additionalViewData: null);
}
@@ -130,7 +131,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -145,7 +146,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Editor(
+ public static IHtmlContent Editor(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string templateName,
@@ -173,7 +174,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// A used to disambiguate the names of HTML elements that are created for
/// properties that have the same name.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -188,7 +189,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString Editor(
+ public static IHtmlContent Editor(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string templateName,
@@ -205,7 +206,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An expression to be evaluated against the current model.
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -216,7 +217,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorFor(
+ public static IHtmlContent EditorFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -237,7 +238,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -248,7 +249,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorFor(
+ public static IHtmlContent EditorFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
object additionalViewData)
@@ -270,7 +271,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The name of the template that is used to create the HTML markup.
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -281,7 +282,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorFor(
+ public static IHtmlContent EditorFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string templateName)
@@ -304,7 +305,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -315,7 +316,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorFor(
+ public static IHtmlContent EditorFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string templateName,
@@ -342,7 +343,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -353,7 +354,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorFor(
+ public static IHtmlContent EditorFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string templateName,
@@ -367,7 +368,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// model's .
///
/// The instance this method extends.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -378,7 +379,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorForModel([NotNull] this IHtmlHelper htmlHelper)
+ public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper)
{
return htmlHelper.Editor(
expression: null,
@@ -397,7 +398,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -408,7 +409,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorForModel([NotNull] this IHtmlHelper htmlHelper, object additionalViewData)
+ public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper, object additionalViewData)
{
return htmlHelper.Editor(
expression: null,
@@ -423,7 +424,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// The name of the template used to create the HTML markup.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -434,7 +435,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorForModel([NotNull] this IHtmlHelper htmlHelper, string templateName)
+ public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper, string templateName)
{
return htmlHelper.Editor(
expression: null,
@@ -455,7 +456,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -466,7 +467,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorForModel(
+ public static IHtmlContent EditorForModel(
[NotNull] this IHtmlHelper htmlHelper,
string templateName,
object additionalViewData)
@@ -489,7 +490,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// A used to disambiguate the names of HTML elements that are created for
/// properties that have the same name.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -500,7 +501,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorForModel(
+ public static IHtmlContent EditorForModel(
[NotNull] this IHtmlHelper htmlHelper,
string templateName,
string htmlFieldName)
@@ -528,7 +529,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// that can contain additional view data that will be merged into the
/// instance created for the template.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -539,7 +540,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
///
///
- public static HtmlString EditorForModel(
+ public static IHtmlContent EditorForModel(
[NotNull] this IHtmlHelper htmlHelper,
string templateName,
string htmlFieldName,
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperInputExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperInputExtensions.cs
index 677729b742..4455fd8ddb 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperInputExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperInputExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.Linq.Expressions;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -18,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// Expression name, relative to the current model.
- /// A new containing the <input> elements.
+ /// A new containing the <input> elements.
///
///
/// Combines and to set checkbox
@@ -48,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// value "checked" if the values is true ; does not include the attribute otherwise.
///
///
- public static HtmlString CheckBox([NotNull] this IHtmlHelper htmlHelper, string expression)
+ public static IHtmlContent CheckBox([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.CheckBox(expression, isChecked: null, htmlAttributes: null);
}
@@ -60,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// Expression name, relative to the current model.
/// If true , checkbox is initially checked.
- /// A new containing the <input> elements.
+ /// A new containing the <input> elements.
///
///
/// Combines and to set checkbox
@@ -91,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// value "checked" if the values is true ; does not include the attribute otherwise.
///
///
- public static HtmlString CheckBox(
+ public static IHtmlContent CheckBox(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
bool isChecked)
@@ -110,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the <input> elements.
+ /// A new containing the <input> elements.
///
///
/// Combines and to set checkbox
@@ -141,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// value "checked" if the values is true ; does not include the attribute otherwise.
///
///
- public static HtmlString CheckBox(
+ public static IHtmlContent CheckBox(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object htmlAttributes)
@@ -155,7 +156,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// An expression to be evaluated against the current model.
- /// A new containing the <input> elements.
+ /// A new containing the <input> elements.
///
///
/// Combines and the string representation of the
@@ -179,7 +180,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// value "checked" if the values is true ; does not include the attribute otherwise.
///
///
- public static HtmlString CheckBoxFor(
+ public static IHtmlContent CheckBoxFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -191,7 +192,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// Expression name, relative to the current model.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -217,7 +218,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString Hidden([NotNull] this IHtmlHelper htmlHelper, string expression)
+ public static IHtmlContent Hidden([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.Hidden(expression, value: null, htmlAttributes: null);
}
@@ -228,7 +229,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// Expression name, relative to the current model.
/// If non-null , value to include in the element.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -255,7 +256,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString Hidden(
+ public static IHtmlContent Hidden(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object value)
@@ -270,7 +271,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An expression to be evaluated against the current model.
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -290,7 +291,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString HiddenFor(
+ public static IHtmlContent HiddenFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -302,13 +303,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// Expression name, relative to the current model.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
/// Combines and to set
/// <input> element's "name" attribute. Sanitizes to set element's "id"
/// attribute. Sets <input> element's "value" attribute to string.Empty .
///
- public static HtmlString Password([NotNull] this IHtmlHelper htmlHelper, string expression)
+ public static IHtmlContent Password([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.Password(expression, value: null, htmlAttributes: null);
}
@@ -319,7 +320,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// Expression name, relative to the current model.
/// If non-null , value to include in the element.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -332,7 +333,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString Password(
+ public static IHtmlContent Password(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object value)
@@ -347,7 +348,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An expression to be evaluated against the current model.
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -363,7 +364,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString PasswordFor(
+ public static IHtmlContent PasswordFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -376,7 +377,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// Expression name, relative to the current model.
/// Value to include in the element. Must not be null .
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -408,7 +409,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the attribute otherwise.
///
///
- public static HtmlString RadioButton(
+ public static IHtmlContent RadioButton(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object value)
@@ -430,7 +431,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -469,7 +470,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the attribute otherwise.
///
///
- public static HtmlString RadioButton(
+ public static IHtmlContent RadioButton(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object value,
@@ -491,7 +492,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// If true , radio button is initially selected. Must not be null if
/// is also null .
///
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -529,7 +530,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the attribute otherwise.
///
///
- public static HtmlString RadioButton(
+ public static IHtmlContent RadioButton(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object value,
@@ -546,7 +547,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Value to include in the element. Must not be null .
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -571,7 +572,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// ; does not include the attribute otherwise.
///
///
- public static HtmlString RadioButtonFor(
+ public static IHtmlContent RadioButtonFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
[NotNull] object value)
@@ -584,7 +585,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// Expression name, relative to the current model.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -610,7 +611,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextBox([NotNull] this IHtmlHelper htmlHelper, string expression)
+ public static IHtmlContent TextBox([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.TextBox(expression, value: null, format: null, htmlAttributes: null);
}
@@ -621,7 +622,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// Expression name, relative to the current model.
/// If non-null , value to include in the element.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -650,7 +651,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextBox(
+ public static IHtmlContent TextBox(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object value)
@@ -667,7 +668,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The composite format (see http://msdn.microsoft.com/en-us/library/txafckwd.aspx).
///
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -701,7 +702,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextBox(
+ public static IHtmlContent TextBox(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object value,
@@ -721,7 +722,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -751,7 +752,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextBox(
+ public static IHtmlContent TextBox(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object value,
@@ -767,7 +768,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An expression to be evaluated against the current model.
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -786,7 +787,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextBoxFor(
+ public static IHtmlContent TextBoxFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -803,7 +804,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -824,7 +825,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextBoxFor(
+ public static IHtmlContent TextBoxFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string format)
@@ -844,7 +845,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -864,7 +865,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextBoxFor(
+ public static IHtmlContent TextBoxFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
object htmlAttributes)
@@ -877,7 +878,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// Expression name, relative to the current model.
- /// A new containing the <textarea> element.
+ /// A new containing the <textarea> element.
///
///
/// Combines and to set
@@ -903,7 +904,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextArea(
+ public static IHtmlContent TextArea(
[NotNull] this IHtmlHelper htmlHelper,
string expression)
{
@@ -920,7 +921,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the <textarea> element.
+ /// A new containing the <textarea> element.
///
///
/// Combines and to set
@@ -946,7 +947,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextArea(
+ public static IHtmlContent TextArea(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object htmlAttributes)
@@ -960,7 +961,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// Expression name, relative to the current model.
/// If non-null , value to include in the element.
- /// A new containing the <textarea> element.
+ /// A new containing the <textarea> element.
///
///
/// Combines and to set
@@ -987,7 +988,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextArea(
+ public static IHtmlContent TextArea(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string value)
@@ -1006,7 +1007,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the <textarea> element.
+ /// A new containing the <textarea> element.
///
///
/// Combines and to set
@@ -1033,7 +1034,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextArea(
+ public static IHtmlContent TextArea(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string value,
@@ -1049,7 +1050,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An expression to be evaluated against the current model.
/// The type of the model.
/// The type of the result.
- /// A new containing the <textarea> element.
+ /// A new containing the <textarea> element.
///
///
/// Combines and the string representation of the
@@ -1068,7 +1069,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextAreaFor(
+ public static IHtmlContent TextAreaFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -1087,7 +1088,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <textarea> element.
+ /// A new containing the <textarea> element.
///
///
/// Combines and the string representation of the
@@ -1106,7 +1107,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- public static HtmlString TextAreaFor(
+ public static IHtmlContent TextAreaFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
object htmlAttributes)
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLabelExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLabelExtensions.cs
index 3bc1288561..85baaa33d1 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLabelExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLabelExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.Linq.Expressions;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -17,8 +18,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// Expression name, relative to the current model.
- /// A new containing the <label> element.
- public static HtmlString Label([NotNull] this IHtmlHelper htmlHelper, string expression)
+ /// A new containing the <label> element.
+ public static IHtmlContent Label([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.Label(expression, labelText: null, htmlAttributes: null);
}
@@ -29,8 +30,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// Expression name, relative to the current model.
/// The inner text of the element.
- /// A new containing the <label> element.
- public static HtmlString Label([NotNull] this IHtmlHelper htmlHelper, string expression, string labelText)
+ /// A new containing the <label> element.
+ public static IHtmlContent Label([NotNull] this IHtmlHelper htmlHelper, string expression, string labelText)
{
return htmlHelper.Label(expression, labelText, htmlAttributes: null);
}
@@ -42,8 +43,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An expression to be evaluated against the current model.
/// The type of the model.
/// The type of the result.
- /// A new containing the <label> element.
- public static HtmlString LabelFor(
+ /// A new containing the <label> element.
+ public static IHtmlContent LabelFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -58,8 +59,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The inner text of the element.
/// The type of the model.
/// The type of the result.
- /// A new containing the <label> element.
- public static HtmlString LabelFor(
+ /// A new containing the <label> element.
+ public static IHtmlContent LabelFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string labelText)
@@ -79,8 +80,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <label> element.
- public static HtmlString LabelFor(
+ /// A new containing the <label> element.
+ public static IHtmlContent LabelFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
object htmlAttributes)
@@ -92,8 +93,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Returns a <label> element for the current model.
///
/// The instance this method extends.
- /// A new containing the <label> element.
- public static HtmlString LabelForModel([NotNull] this IHtmlHelper htmlHelper)
+ /// A new containing the <label> element.
+ public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper)
{
return htmlHelper.Label(expression: null, labelText: null, htmlAttributes: null);
}
@@ -103,8 +104,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// The inner text of the element.
- /// A new containing the <label> element.
- public static HtmlString LabelForModel([NotNull] this IHtmlHelper htmlHelper, string labelText)
+ /// A new containing the <label> element.
+ public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper, string labelText)
{
return htmlHelper.Label(expression: null, labelText: labelText, htmlAttributes: null);
}
@@ -118,8 +119,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the <label> element.
- public static HtmlString LabelForModel([NotNull] this IHtmlHelper htmlHelper, object htmlAttributes)
+ /// A new containing the <label> element.
+ public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper, object htmlAttributes)
{
return htmlHelper.Label(expression: null, labelText: null, htmlAttributes: htmlAttributes);
}
@@ -134,8 +135,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the <label> element.
- public static HtmlString LabelForModel(
+ /// A new containing the <label> element.
+ public static IHtmlContent LabelForModel(
[NotNull] this IHtmlHelper htmlHelper,
string labelText,
object htmlAttributes)
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLinkExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLinkExtensions.cs
index 60aa82ebe7..1314c870e9 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLinkExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperLinkExtensions.cs
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -16,8 +17,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// The inner text of the anchor element. Must not be null .
/// The name of the action.
- /// A new containing the anchor element.
- public static HtmlString ActionLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
string actionName)
@@ -46,8 +47,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the route
/// parameters.
///
- /// A new containing the anchor element.
- public static HtmlString ActionLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
string actionName,
@@ -82,8 +83,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the anchor element.
- public static HtmlString ActionLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
string actionName,
@@ -108,8 +109,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The inner text of the anchor element. Must not be null .
/// The name of the action.
/// The name of the controller.
- /// A new containing the anchor element.
- public static HtmlString ActionLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
string actionName,
@@ -140,8 +141,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the route
/// parameters.
///
- /// A new containing the anchor element.
- public static HtmlString ActionLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
string actionName,
@@ -178,8 +179,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the anchor element.
- public static HtmlString ActionLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
string actionName,
@@ -210,8 +211,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the route
/// parameters.
///
- /// A new containing the anchor element.
- public static HtmlString RouteLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
object routeValues)
@@ -232,8 +233,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// The inner text of the anchor element. Must not be null .
/// The name of the route.
- /// A new containing the anchor element.
- public static HtmlString RouteLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
string routeName)
@@ -261,8 +262,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the route
/// parameters.
///
- /// A new containing the anchor element.
- public static HtmlString RouteLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
string routeName,
@@ -295,8 +296,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the anchor element.
- public static HtmlString RouteLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
object routeValues,
@@ -330,8 +331,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML
/// attributes.
///
- /// A new containing the anchor element.
- public static HtmlString RouteLink(
+ /// A new containing the anchor element.
+ public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
string routeName,
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperSelectExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperSelectExtensions.cs
index 417d5874ad..3a8fe1f79a 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperSelectExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperSelectExtensions.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -18,13 +19,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// Expression name, relative to the current model.
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- public static HtmlString DropDownList([NotNull] this IHtmlHelper htmlHelper, string expression)
+ public static IHtmlContent DropDownList([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.DropDownList(expression, selectList: null, optionLabel: null, htmlAttributes: null);
}
@@ -38,13 +39,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The text for a default empty item. Does not include such an item if argument is null .
///
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- public static HtmlString DropDownList(
+ public static IHtmlContent DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string optionLabel)
@@ -66,13 +67,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// A collection of objects used to populate the <select> element with
/// <optgroup> and <option> elements.
///
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- public static HtmlString DropDownList(
+ public static IHtmlContent DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
IEnumerable selectList)
@@ -94,13 +95,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the <select> element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- public static HtmlString DropDownList(
+ public static IHtmlContent DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
IEnumerable selectList,
@@ -122,13 +123,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The text for a default empty item. Does not include such an item if argument is null .
///
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- public static HtmlString DropDownList(
+ public static IHtmlContent DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
IEnumerable selectList,
@@ -149,13 +150,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and the string representation of the
/// to set <select> element's "name" attribute. Sanitizes the string
/// representation of the to set element's "id" attribute.
///
- public static HtmlString DropDownListFor(
+ public static IHtmlContent DropDownListFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
IEnumerable selectList)
@@ -179,13 +180,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and the string representation of the
/// to set <select> element's "name" attribute. Sanitizes the string
/// representation of the to set element's "id" attribute.
///
- public static HtmlString DropDownListFor(
+ public static IHtmlContent DropDownListFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
IEnumerable selectList,
@@ -213,13 +214,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and the string representation of the
/// to set <select> element's "name" attribute. Sanitizes the string
/// representation of the to set element's "id" attribute.
///
- public static HtmlString DropDownListFor(
+ public static IHtmlContent DropDownListFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
IEnumerable selectList,
@@ -233,13 +234,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
/// Expression name, relative to the current model.
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- public static HtmlString ListBox([NotNull] this IHtmlHelper htmlHelper, string expression)
+ public static IHtmlContent ListBox([NotNull] this IHtmlHelper htmlHelper, string expression)
{
return htmlHelper.ListBox(expression, selectList: null, htmlAttributes: null);
}
@@ -254,13 +255,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// A collection of objects used to populate the <select> element with
/// <optgroup> and <option> elements.
///
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- public static HtmlString ListBox(
+ public static IHtmlContent ListBox(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
IEnumerable selectList)
@@ -280,13 +281,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the model.
/// The type of the result.
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and the string representation of the
/// to set <select> element's "name" attribute. Sanitizes the string
/// representation of the to set element's "id" attribute.
///
- public static HtmlString ListBoxFor(
+ public static IHtmlContent ListBoxFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
IEnumerable selectList)
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValidationExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValidationExtensions.cs
index 0619f8914c..c68b3a0f7c 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValidationExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlHelperValidationExtensions.cs
@@ -3,6 +3,7 @@
using System;
using System.Linq.Expressions;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -19,14 +20,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// Expression name, relative to the current model.
///
- /// A new containing a element.
+ /// A new containing a element.
/// null if the is valid and client-side validation is disabled.
///
///
/// Method extracts an error string from the object. Message
/// will always be visible but client-side validation may update the associated CSS class.
///
- public static HtmlString ValidationMessage(
+ public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
string expression)
{
@@ -45,10 +46,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// validation may update the associated CSS class.
///
///
- /// A new containing a element.
+ /// A new containing a element.
/// null if the is valid and client-side validation is disabled.
///
- public static HtmlString ValidationMessage(
+ public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string message)
@@ -69,14 +70,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// attributes.
///
///
- /// A new containing a element.
+ /// A new containing a element.
/// null if the is valid and client-side validation is disabled.
///
///
/// Method extracts an error string from the object. Message
/// will always be visible but client-side validation may update the associated CSS class.
///
- public static HtmlString ValidationMessage(
+ public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
object htmlAttributes)
@@ -100,10 +101,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// .
///
///
- /// A new containing a element. null if the
+ /// A new containing a element. null if the
/// is valid and client-side validation is disabled.
///
- public static HtmlString ValidationMessage(
+ public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string message,
@@ -130,10 +131,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// attributes.
///
///
- /// A new containing a element.
+ /// A new containing a element.
/// null if the is valid and client-side validation is disabled.
///
- public static HtmlString ValidationMessage(
+ public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
string expression,
string message,
@@ -151,14 +152,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The type of the model.
/// The type of the result.
///
- /// A new containing a element.
+ /// A new containing a element.
/// null if the is valid and client-side validation is disabled.
///
///
/// Method extracts an error string from the object. Message
/// will always be visible but client-side validation may update the associated CSS class.
///
- public static HtmlString ValidationMessageFor(
+ public static IHtmlContent ValidationMessageFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression)
{
@@ -179,10 +180,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The type of the model.
/// The type of the result.
///
- /// A new containing a element.
+ /// A new containing a element.
/// null if the is valid and client-side validation is disabled.
///
- public static HtmlString ValidationMessageFor(
+ public static IHtmlContent ValidationMessageFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string message)
@@ -210,10 +211,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The type of the model.
/// The type of the result.
///
- /// A new containing a element.
+ /// A new containing a element.
/// null if the is valid and client-side validation is disabled.
///
- public static HtmlString ValidationMessageFor(
+ public static IHtmlContent ValidationMessageFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string message,
@@ -240,10 +241,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The type of the model.
/// The type of the result.
///
- /// A new containing the element. null if the
+ /// A new containing the element. null if the
/// is valid and client-side validation is disabled.
///
- public static HtmlString ValidationMessageFor(
+ public static IHtmlContent ValidationMessageFor(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] Expression> expression,
string message,
@@ -258,10 +259,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The instance this method extends.
///
- /// New containing a <div> element wrapping the <ul> element.
+ /// New containing a <div> element wrapping the <ul> element.
/// if the current model is valid and client-side validation is disabled).
///
- public static HtmlString ValidationSummary([NotNull] this IHtmlHelper htmlHelper)
+ public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper)
{
return htmlHelper.ValidationSummary(
excludePropertyErrors: false,
@@ -279,10 +280,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// If true , display model-level errors only; otherwise display all errors.
///
///
- /// New containing a <div> element wrapping the <ul> element.
+ /// New containing a <div> element wrapping the <ul> element.
/// if the current model is valid and client-side validation is disabled).
///
- public static HtmlString ValidationSummary([NotNull] this IHtmlHelper htmlHelper, bool excludePropertyErrors)
+ public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, bool excludePropertyErrors)
{
return htmlHelper.ValidationSummary(
excludePropertyErrors,
@@ -298,12 +299,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// The instance this method extends.
/// The message to display with the validation summary.
///
- /// New containing a <div> element wrapping the
+ /// New containing a <div> element wrapping the
/// element (which wraps the
/// ) and the <ul> element. if the current model
/// is valid and client-side validation is disabled).
///
- public static HtmlString ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message)
+ public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message)
{
return htmlHelper.ValidationSummary(
excludePropertyErrors: false,
@@ -323,11 +324,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// .
///
///
- /// New containing a <div> element wrapping the element
+ /// New containing a <div> element wrapping the element
/// and the <ul> element. if the current model is valid and client-side
/// validation is disabled).
///
- public static HtmlString ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message, string tag)
+ public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message, string tag)
{
return htmlHelper.ValidationSummary(
excludePropertyErrors: false,
@@ -346,12 +347,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The message to display with the validation summary.
///
- /// New containing a <div> element wrapping the
+ /// New containing a <div> element wrapping the
/// element (which, in turn, wraps the
/// ) and the <ul> element. if the current model
/// is valid and client-side validation is disabled).
///
- public static HtmlString ValidationSummary(
+ public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
bool excludePropertyErrors,
string message)
@@ -375,12 +376,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the HTML attributes.
///
///
- /// New containing a <div> element wrapping the
+ /// New containing a <div> element wrapping the
/// element (which wraps the
/// ) and the <ul> element. if the current model
/// is valid and client-side validation is disabled).
///
- public static HtmlString ValidationSummary(
+ public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
string message,
object htmlAttributes)
@@ -408,11 +409,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// .
///
///
- /// New containing a <div> element wrapping the element
+ /// New containing a <div> element wrapping the element
/// and the <ul> element. if the current model is valid and client-side
/// validation is disabled).
///
- public static HtmlString ValidationSummary(
+ public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
string message,
object htmlAttributes,
@@ -439,11 +440,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// .
///
///
- /// New containing a <div> element wrapping the element
+ /// New containing a <div> element wrapping the element
/// and the <ul> element. if the current model is valid and client-side
/// validation is disabled).
///
- public static HtmlString ValidationSummary(
+ public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
bool excludePropertyErrors,
string message,
@@ -471,12 +472,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the HTML attributes.
///
///
- /// New containing a <div> element wrapping the
+ /// New containing a <div> element wrapping the
/// element (which wraps the
/// ) and the <ul> element. if the current model
/// is valid and client-side validation is disabled).
///
- public static HtmlString ValidationSummary(
+ public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
bool excludePropertyErrors,
string message,
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs
index 4d8ebb4b3b..8fe7dea830 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs
@@ -3,6 +3,7 @@
using System.IO;
using Microsoft.AspNet.Html.Abstractions;
+using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -12,36 +13,24 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
public class HtmlString : IHtmlContent
{
- private static readonly HtmlString _empty = new HtmlString(string.Empty);
private readonly string _input;
///
- /// Instantiates a new instance of .
+ /// Returns an with empty content.
///
- /// string to initialize .
+ public static readonly HtmlString Empty = new HtmlString(string.Empty);
+
+ ///
+ /// Creates a new instance of .
+ ///
+ /// string to initialize .
public HtmlString(string input)
{
_input = input;
}
- ///
- /// Returns an with empty content.
- ///
- public static HtmlString Empty
- {
- get
- {
- return _empty;
- }
- }
-
- ///
- /// Writes the value in this instance of to the target
- /// .
- ///
- /// The to write contents to.
- /// The with which the output must be encoded.
- public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
+ ///
+ public void WriteTo([NotNull] TextWriter writer, [NotNull] IHtmlEncoder encoder)
{
writer.Write(_input);
}
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelper.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelper.cs
index 127639c757..2f277efe89 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelper.cs
@@ -54,11 +54,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
ITempDataDictionary TempData { get; }
- ///
- /// Gets the to be used for encoding HTML.
- ///
- IHtmlEncoder HtmlEncoder { get; }
-
///
/// Gets the to be used for encoding a URL.
///
@@ -88,8 +83,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the anchor element.
- HtmlString ActionLink(
+ /// A new containing the anchor element.
+ IHtmlContent ActionLink(
[NotNull] string linkText,
string actionName,
string controllerName,
@@ -103,8 +98,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Returns a <hidden> element (antiforgery token) that will be validated when the containing
/// <form> is submitted.
///
- /// A new containing the <hidden> element.
- HtmlString AntiForgeryToken();
+ /// containing the <hidden> element.
+ IHtmlContent AntiForgeryToken();
///
/// Renders a <form> start tag to the response. When the user submits the form, the action with name
@@ -174,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the checkbox element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <input> elements.
+ /// A new containing the <input> elements.
///
///
/// Combines and to set checkbox
@@ -206,7 +201,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// value "checked" if the values is true ; does not include the attribute otherwise.
///
///
- HtmlString CheckBox(string expression, bool? isChecked, object htmlAttributes);
+ IHtmlContent CheckBox(string expression, bool? isChecked, object htmlAttributes);
///
/// Returns HTML markup for the , using a display template, specified HTML field
@@ -227,7 +222,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// view data that will be merged into the instance created for the
/// template.
///
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
///
/// For example the default display template includes markup for each property in the
@@ -238,7 +233,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// "prop" which identifies the current model's "prop" property.
///
///
- HtmlString Display(
+ IHtmlContent Display(
string expression,
string templateName,
string htmlFieldName,
@@ -277,13 +272,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the <select> element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- HtmlString DropDownList(
+ IHtmlContent DropDownList(
string expression,
IEnumerable selectList,
string optionLabel,
@@ -308,7 +303,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// view data that will be merged into the instance created for the
/// template.
///
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
///
/// For example the default editor template includes <label> and <input>
@@ -319,7 +314,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// "prop" which identifies the current model's "prop" property.
///
///
- HtmlString Editor(string expression, string templateName, string htmlFieldName, object additionalViewData);
+ IHtmlContent Editor(string expression, string templateName, string htmlFieldName, object additionalViewData);
///
/// Converts the to an HTML-encoded .
@@ -417,7 +412,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -445,7 +440,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- HtmlString Hidden(string expression, object value, object htmlAttributes);
+ IHtmlContent Hidden(string expression, object value, object htmlAttributes);
///
/// Returns the HTML element Id for the specified .
@@ -463,8 +458,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <label> element.
- HtmlString Label(string expression, string labelText, object htmlAttributes);
+ /// A new containing the <label> element.
+ IHtmlContent Label(string expression, string labelText, object htmlAttributes);
///
/// Returns a multi-selection <select> element for the , using the
@@ -479,13 +474,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the <select> element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and to set
/// <select> element's "name" attribute. Sanitizes to set element's "id"
/// attribute.
///
- HtmlString ListBox(string expression, IEnumerable selectList, object htmlAttributes);
+ IHtmlContent ListBox(string expression, IEnumerable selectList, object htmlAttributes);
///
/// Returns the full HTML element name for the specified .
@@ -517,7 +512,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -531,7 +526,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- HtmlString Password(string expression, object value, object htmlAttributes);
+ IHtmlContent Password(string expression, object value, object htmlAttributes);
///
/// Returns an <input> element of type "radio" for the specified .
@@ -551,7 +546,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -591,23 +586,23 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the attribute otherwise.
///
///
- HtmlString RadioButton(string expression, object value, bool? isChecked, object htmlAttributes);
+ IHtmlContent RadioButton(string expression, object value, bool? isChecked, object htmlAttributes);
///
/// Wraps HTML markup in an , without HTML-encoding the specified
/// .
///
/// HTML markup .
- /// A new containing the wrapped .
- HtmlString Raw(string value);
+ /// A new containing the wrapped .
+ IHtmlContent Raw(string value);
///
/// Wraps HTML markup from the string representation of an in an
/// , without HTML-encoding the string representation.
///
/// The to wrap.
- /// A new containing the wrapped string representation.
- HtmlString Raw(object value);
+ /// containing the wrapped string representation.
+ IHtmlContent Raw(object value);
///
/// Renders HTML markup for the specified partial view.
@@ -641,8 +636,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the anchor element.
- HtmlString RouteLink(
+ /// A new containing the anchor element.
+ IHtmlContent RouteLink(
[NotNull] string linkText,
string routeName,
string protocol,
@@ -662,7 +657,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <textarea> element.
+ /// A new containing the <textarea> element.
///
///
/// Combines and to set
@@ -689,7 +684,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- HtmlString TextArea(string expression, string value, int rows, int columns, object htmlAttributes);
+ IHtmlContent TextArea(string expression, string value, int rows, int columns, object htmlAttributes);
///
/// Returns an <input> element of type "text" for the specified .
@@ -703,7 +698,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and to set
@@ -737,7 +732,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- HtmlString TextBox(string current, object value, string format, object htmlAttributes);
+ IHtmlContent TextBox(string current, object value, string format, object htmlAttributes);
///
/// Returns the validation message if an error exists in the object
@@ -758,10 +753,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// .
///
///
- /// A new containing a element. null if the
+ /// A new containing a element. null if the
/// is valid and client-side validation is disabled.
///
- HtmlString ValidationMessage(string expression, string message, object htmlAttributes, string tag);
+ IHtmlContent ValidationMessage(string expression, string message, object htmlAttributes, string tag);
///
/// Returns an unordered list (<ul> element) of validation messages that are in the
@@ -780,11 +775,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// .
///
///
- /// New containing a <div> element wrapping the element
+ /// New containing a <div> element wrapping the element
/// and the <ul> element. if the current model is valid and client-side
/// validation is disabled).
///
- HtmlString ValidationSummary(
+ IHtmlContent ValidationSummary(
bool excludePropertyErrors,
string message,
object htmlAttributes,
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelperOfT.cs
index 5640d13f50..fcea74ea8b 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelperOfT.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/IHtmlHelperOfT.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -28,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// An that contains the HTML attributes for the checkbox element. Alternatively, an
/// instance containing the HTML attributes.
///
- /// A new containing the <input> elements.
+ /// A new containing the <input> elements.
///
///
/// Combines and the string representation of the
@@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// if the values is true ; does not include the attribute otherwise.
///
///
- HtmlString CheckBoxFor([NotNull] Expression> expression, object htmlAttributes);
+ IHtmlContent CheckBoxFor([NotNull] Expression> expression, object htmlAttributes);
///
/// Returns HTML markup for the , using a display template, specified HTML field
@@ -72,12 +73,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// template.
///
/// The type of the result.
- /// A new containing the created HTML.
+ /// A new containing the created HTML.
///
/// For example the default display template includes markup for each property in the
/// result.
///
- HtmlString DisplayFor(
+ IHtmlContent DisplayFor(
[NotNull] Expression> expression,
string templateName,
string htmlFieldName,
@@ -131,13 +132,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML attributes.
///
/// The type of the result.
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and the string representation of the
/// to set <select> element's "name" attribute. Sanitizes the string
/// representation of the to set element's "id" attribute.
///
- HtmlString DropDownListFor(
+ IHtmlContent DropDownListFor(
[NotNull] Expression> expression,
IEnumerable selectList,
string optionLabel,
@@ -160,12 +161,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// template.
///
/// The type of the result.
- /// A new containing the <input> element(s).
+ /// A new containing the <input> element(s).
///
/// For example the default editor template includes <label> and <input>
/// elements for each property in the result.
///
- HtmlString EditorFor(
+ IHtmlContent EditorFor(
[NotNull] Expression> expression,
string templateName,
string htmlFieldName,
@@ -186,7 +187,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML attributes.
///
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -207,7 +208,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- HtmlString HiddenFor(
+ IHtmlContent HiddenFor(
[NotNull] Expression> expression,
object htmlAttributes);
@@ -229,8 +230,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML attributes.
///
/// The type of the result.
- /// A new containing the <label> element.
- HtmlString LabelFor(
+ /// A new containing the <label> element.
+ IHtmlContent LabelFor(
[NotNull] Expression> expression,
string labelText,
object htmlAttributes);
@@ -249,13 +250,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML attributes.
///
/// The type of the result.
- /// A new containing the <select> element.
+ /// A new containing the <select> element.
///
/// Combines and the string representation of the
/// to set <select> element's "name" attribute. Sanitizes the string
/// representation of the to set element's "id" attribute.
///
- HtmlString ListBoxFor(
+ IHtmlContent ListBoxFor(
[NotNull] Expression> expression,
IEnumerable selectList,
object htmlAttributes);
@@ -277,7 +278,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML attributes.
///
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -294,7 +295,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- HtmlString PasswordFor(
+ IHtmlContent PasswordFor(
[NotNull] Expression> expression,
object htmlAttributes);
@@ -308,7 +309,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML attributes.
///
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -334,16 +335,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// ; does not include the attribute otherwise.
///
///
- HtmlString RadioButtonFor(
+ IHtmlContent RadioButtonFor(
[NotNull] Expression> expression,
[NotNull] object value,
object htmlAttributes);
///
- new HtmlString Raw(object value);
+ new IHtmlContent Raw(object value);
///
- new HtmlString Raw(string value);
+ new IHtmlContent Raw(string value);
///
/// Returns a <textarea> element for the specified .
@@ -356,7 +357,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML attributes.
///
/// The type of the result.
- /// A new containing the <textarea> element.
+ /// A new containing the <textarea> element.
///
///
/// Combines and the string representation of the
@@ -375,7 +376,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- HtmlString TextAreaFor(
+ IHtmlContent TextAreaFor(
[NotNull] Expression> expression,
int rows,
int columns,
@@ -393,7 +394,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// instance containing the HTML attributes.
///
/// The type of the result.
- /// A new containing the <input> element.
+ /// A new containing the <input> element.
///
///
/// Combines and the string representation of the
@@ -415,7 +416,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// - Otherwise,
string.Empty .
///
///
- HtmlString TextBoxFor(
+ IHtmlContent TextBoxFor(
[NotNull] Expression> expression,
string format,
object htmlAttributes);
@@ -440,10 +441,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
/// The type of the result.
///
- /// A new containing the element. null if the
+ /// A new containing the element. null if the
/// is valid and client-side validation is disabled.
///
- HtmlString ValidationMessageFor(
+ IHtmlContent ValidationMessageFor(
[NotNull] Expression> expression,
string message,
object htmlAttributes,
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Internal/TemplateBuilder.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Internal/TemplateBuilder.cs
index d2099dc952..44b00c1a4e 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Internal/TemplateBuilder.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Internal/TemplateBuilder.cs
@@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Globalization;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
@@ -42,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.Rendering.Internal
_metadata = modelExplorer.Metadata;
}
- public string Build()
+ public IHtmlContent Build()
{
if (_metadata.ConvertEmptyStringToNull && string.Empty.Equals(_model))
{
@@ -66,7 +67,7 @@ namespace Microsoft.AspNet.Mvc.Rendering.Internal
// don't check to make sure that the object hasn't already been displayed
if (_viewData.TemplateInfo.Visited(_modelExplorer))
{
- return string.Empty;
+ return HtmlString.Empty;
}
// We need to copy the ModelExplorer to copy the model metadata. Otherwise we might
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Internal/TemplateRenderer.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Internal/TemplateRenderer.cs
index 09c7aa2228..0c792268d6 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Internal/TemplateRenderer.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/Internal/TemplateRenderer.cs
@@ -4,10 +4,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
using System.Linq;
using System.Reflection;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ViewFeatures;
@@ -22,8 +21,8 @@ namespace Microsoft.AspNet.Mvc.Rendering.Internal
private const string EditorTemplateViewPath = "EditorTemplates";
public const string IEnumerableOfIFormFileName = "IEnumerable`" + nameof(IFormFile);
- private static readonly Dictionary> _defaultDisplayActions =
- new Dictionary>(StringComparer.OrdinalIgnoreCase)
+ private static readonly Dictionary> _defaultDisplayActions =
+ new Dictionary>(StringComparer.OrdinalIgnoreCase)
{
{ "Collection", DefaultDisplayTemplates.CollectionTemplate },
{ "EmailAddress", DefaultDisplayTemplates.EmailAddressTemplate },
@@ -37,8 +36,8 @@ namespace Microsoft.AspNet.Mvc.Rendering.Internal
{ typeof(object).Name, DefaultDisplayTemplates.ObjectTemplate },
};
- private static readonly Dictionary> _defaultEditorActions =
- new Dictionary>(StringComparer.OrdinalIgnoreCase)
+ private static readonly Dictionary> _defaultEditorActions =
+ new Dictionary>(StringComparer.OrdinalIgnoreCase)
{
{ "Collection", DefaultEditorTemplates.CollectionTemplate },
{ "EmailAddress", DefaultEditorTemplates.EmailAddressInputTemplate },
@@ -88,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.Rendering.Internal
_readOnly = readOnly;
}
- public string Render()
+ public IHtmlContent Render()
{
var defaultActions = GetDefaultActions();
var modeViewPath = _readOnly ? DisplayTemplateViewPath : EditorTemplateViewPath;
@@ -100,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.Rendering.Internal
var viewEngineResult = _viewEngine.FindPartialView(_viewContext, fullViewName);
if (viewEngineResult.Success)
{
- using (var writer = new StringWriter(CultureInfo.InvariantCulture))
+ using (var writer = new StringCollectionTextWriter(_viewContext.Writer.Encoding))
{
// Forcing synchronous behavior so users don't have to await templates.
var view = viewEngineResult.View;
@@ -109,12 +108,12 @@ namespace Microsoft.AspNet.Mvc.Rendering.Internal
var viewContext = new ViewContext(_viewContext, viewEngineResult.View, _viewData, writer);
var renderTask = viewEngineResult.View.RenderAsync(viewContext);
renderTask.GetAwaiter().GetResult();
- return writer.ToString();
+ return writer.Content;
}
}
}
- Func defaultAction;
+ Func defaultAction;
if (defaultActions.TryGetValue(viewName, out defaultAction))
{
return defaultAction(MakeHtmlHelper(_viewContext, _viewData));
@@ -125,7 +124,7 @@ namespace Microsoft.AspNet.Mvc.Rendering.Internal
Resources.FormatTemplateHelpers_NoTemplate(_viewData.ModelExplorer.ModelType.FullName));
}
- private Dictionary> GetDefaultActions()
+ private Dictionary> GetDefaultActions()
{
return _readOnly ? _defaultDisplayActions : _defaultEditorActions;
}
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/StringCollectionTextWriter.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/StringCollectionTextWriter.cs
index 8f4b3f576e..fe7b711f60 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/StringCollectionTextWriter.cs
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/StringCollectionTextWriter.cs
@@ -172,7 +172,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
///
public override string ToString()
{
- return string.Join(string.Empty, Content);
+ using (var writer = new StringWriter())
+ {
+ Content.WriteTo(writer, HtmlEncoder.Default);
+ return writer.ToString();
+ }
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/StringHtmlContent.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/StringHtmlContent.cs
new file mode 100644
index 0000000000..1604142348
--- /dev/null
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/StringHtmlContent.cs
@@ -0,0 +1,39 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.IO;
+using Microsoft.AspNet.Html.Abstractions;
+using Microsoft.Framework.Internal;
+using Microsoft.Framework.WebEncoders;
+
+namespace Microsoft.AspNet.Mvc.Rendering
+{
+ ///
+ /// String content which gets encoded when written.
+ ///
+ public class StringHtmlContent : IHtmlContent
+ {
+ private readonly string _input;
+
+ ///
+ /// Creates a new instance of
+ ///
+ /// to be HTML encoded when is called.
+ public StringHtmlContent(string input)
+ {
+ _input = input;
+ }
+
+ ///
+ public void WriteTo([NotNull] TextWriter writer, [NotNull] IHtmlEncoder encoder)
+ {
+ encoder.HtmlEncode(_input, writer);
+ }
+
+ ///
+ public override string ToString()
+ {
+ return _input;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/project.json b/src/Microsoft.AspNet.Mvc.ViewFeatures/project.json
index 5e726e26ce..ded85b5abf 100644
--- a/src/Microsoft.AspNet.Mvc.ViewFeatures/project.json
+++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/project.json
@@ -15,6 +15,7 @@
"Microsoft.AspNet.Mvc.Core": "6.0.0-*",
"Microsoft.AspNet.Mvc.DataAnnotations": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-*",
+ "Microsoft.Framework.BufferedHtmlContent.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.CopyOnWriteDictionary.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" },
diff --git a/test/Microsoft.AspNet.Mvc.ApiExplorer.Test/project.json b/test/Microsoft.AspNet.Mvc.ApiExplorer.Test/project.json
index 4bbf7d2763..47eee2ef7a 100644
--- a/test/Microsoft.AspNet.Mvc.ApiExplorer.Test/project.json
+++ b/test/Microsoft.AspNet.Mvc.ApiExplorer.Test/project.json
@@ -8,6 +8,7 @@
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*",
"Microsoft.Framework.Logging.Testing": "1.0.0-*",
+ "Microsoft.Framework.WebEncoders.Testing": "1.0.0-*",
"Moq": "4.2.1312.1622",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json
index e6b25ee84d..5d685a8250 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/project.json
@@ -45,6 +45,7 @@
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
"Microsoft.Framework.Configuration.Json": "1.0.0-*",
+ "Microsoft.Framework.WebEncoders.Testing": "1.0.0-*",
"ModelBindingWebSite": "1.0.0",
"MvcSample.Web": "1.0.0",
"PrecompilationWebSite": "1.0.0",
diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/project.json b/test/Microsoft.AspNet.Mvc.IntegrationTests/project.json
index 36f92b84f0..d33da2216d 100644
--- a/test/Microsoft.AspNet.Mvc.IntegrationTests/project.json
+++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/project.json
@@ -10,6 +10,7 @@
"type": "build"
},
"Microsoft.AspNet.Testing": "1.0.0-*",
+ "Microsoft.Framework.WebEncoders.Testing": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"commands": {
diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/project.json b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/project.json
index df8207cad6..0bfd41746d 100644
--- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/project.json
+++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/project.json
@@ -8,6 +8,7 @@
"Microsoft.AspNet.Mvc.ViewFeatures": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestCommon": { "version": "6.0.0-*", "type": "build" },
"Microsoft.AspNet.Testing": "1.0.0-*",
+ "Microsoft.Framework.WebEncoders.Testing": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"commands": {
diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
index d9830f7a37..2f3238abd7 100644
--- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
@@ -4,11 +4,11 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Rendering;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.PageExecutionInstrumentation;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.AspNet.Testing;
@@ -181,7 +181,9 @@ namespace Microsoft.AspNet.Mvc.Razor
// Assert
var content = Assert.IsType(returnValue);
Assert.Equal("HtmlEncode[[Hello ]]HtmlEncode[[World!]]", content.GetContent());
- Assert.Equal(new[] { "HtmlEncode[[Hello ]]", "HtmlEncode[[World!]]" }, content.ToArray());
+ Assert.Equal(
+ "HtmlEncode[[Hello ]]HtmlEncode[[World!]]",
+ HtmlContentUtilities.HtmlContentToString(content));
}, viewContext);
await page.ExecuteAsync();
}
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs
index 32354a5847..d518a7962a 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs
@@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
"hello=world",
It.IsAny>(),
null))
- .Returns(new TagBuilder("a", new CommonTestEncoder()))
+ .Returns(new TagBuilder("a"))
.Verifiable();
var anchorTagHelper = new AnchorTagHelper(generator.Object)
{
@@ -163,7 +163,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
"hello=world",
It.IsAny>(),
null))
- .Returns(new TagBuilder("a", new CommonTestEncoder()))
+ .Returns(new TagBuilder("a"))
.Verifiable();
var anchorTagHelper = new AnchorTagHelper(generator.Object)
{
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs
index a5acd3ea21..7be9506bd4 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs
@@ -121,7 +121,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
It.IsAny(),
It.IsAny(),
It.IsAny()))
- .Returns(new TagBuilder("form", new CommonTestEncoder()));
+ .Returns(new TagBuilder("form"));
generator.Setup(mock => mock.GenerateAntiforgery(viewContext))
.Returns(new HtmlString(" "));
@@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
routeValue = Assert.Single(routeValueDictionary, attr => attr.Key.Equals("-Name"));
Assert.Equal("Value", routeValue.Value);
})
- .Returns(new TagBuilder("form", new CommonTestEncoder()))
+ .Returns(new TagBuilder("form"))
.Verifiable();
var formTagHelper = new FormTagHelper(generator.Object)
{
@@ -244,7 +244,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
It.IsAny>(),
null,
null))
- .Returns(new TagBuilder("form", new CommonTestEncoder()))
+ .Returns(new TagBuilder("form"))
.Verifiable();
var formTagHelper = new FormTagHelper(generator.Object)
{
@@ -294,7 +294,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
It.Is>(m => string.Equals(m["name"], "value")),
null,
null))
- .Returns(new TagBuilder("form", new CommonTestEncoder()))
+ .Returns(new TagBuilder("form"))
.Verifiable();
var formTagHelper = new FormTagHelper(generator.Object)
{
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs
index 763ccaf99d..9d43b76a70 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs
@@ -4,12 +4,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
+using System.IO;
using System.Linq;
using System.Threading.Tasks;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.Rendering.Internal;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.Framework.WebEncoders.Testing;
using Moq;
@@ -104,7 +107,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Assert
Assert.Empty(output.Attributes); // Moved to Content and cleared
- Assert.Equal(expectedContent, output.Content.GetContent());
+ Assert.Equal(expectedContent, HtmlContentUtilities.HtmlContentToString(output.Content));
Assert.True(output.SelfClosing);
Assert.Null(output.TagName); // Cleared
}
@@ -276,7 +279,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var htmlGenerator = new Mock(MockBehavior.Strict);
var tagHelper = GetTagHelper(htmlGenerator.Object, model: false, propertyName: nameof(Model.IsACar));
- var tagBuilder = new TagBuilder("input", new CommonTestEncoder())
+ var tagBuilder = new TagBuilder("input")
{
Attributes =
{
@@ -297,7 +300,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
tagHelper.ViewContext,
tagHelper.For.ModelExplorer,
tagHelper.For.Name))
- .Returns(new TagBuilder("hidden", new NullTestEncoder()))
+ .Returns(new TagBuilder("hidden"))
.Verifiable();
// Act
@@ -308,7 +311,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Empty(output.Attributes); // Moved to Content and cleared
Assert.Equal(expectedPreContent, output.PreContent.GetContent());
- Assert.Equal(expectedContent, output.Content.GetContent());
+ Assert.Equal(expectedContent, HtmlContentUtilities.HtmlContentToString(output.Content));
Assert.Equal(expectedPostContent, output.PostContent.GetContent());
Assert.True(output.SelfClosing);
Assert.Null(output.TagName); // Cleared
@@ -381,7 +384,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
metadataProvider: metadataProvider);
tagHelper.InputTypeName = inputTypeName;
- var tagBuilder = new TagBuilder("input", new NullTestEncoder())
+ var tagBuilder = new TagBuilder("input")
{
Attributes =
{
@@ -480,7 +483,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
metadataProvider: metadataProvider);
tagHelper.InputTypeName = inputTypeName;
- var tagBuilder = new TagBuilder("input", new NullTestEncoder())
+ var tagBuilder = new TagBuilder("input")
{
Attributes =
{
@@ -570,7 +573,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
tagHelper.InputTypeName = inputTypeName;
tagHelper.Value = value;
- var tagBuilder = new TagBuilder("input", new NullTestEncoder())
+ var tagBuilder = new TagBuilder("input")
{
Attributes =
{
@@ -683,7 +686,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
metadataProvider: metadataProvider);
tagHelper.InputTypeName = inputTypeName;
- var tagBuilder = new TagBuilder("input", new NullTestEncoder())
+ var tagBuilder = new TagBuilder("input")
{
Attributes =
{
@@ -791,7 +794,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
propertyName: nameof(Model.Text),
metadataProvider: metadataProvider);
- var tagBuilder = new TagBuilder("input", new NullTestEncoder());
+ var tagBuilder = new TagBuilder("input");
var htmlAttributes = new Dictionary
{
@@ -820,9 +823,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.True(output.SelfClosing);
Assert.Equal(expectedAttributes, output.Attributes);
- Assert.Empty(output.PreContent);
- Assert.Equal(new[] { string.Empty }, output.Content);
- Assert.Empty(output.PostContent);
+ Assert.Empty(output.PreContent.GetContent());
+ Assert.Equal(string.Empty, output.Content.GetContent());
+ Assert.Empty(output.PostContent.GetContent());
Assert.Equal(expectedTagName, output.TagName);
}
@@ -875,7 +878,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
metadataProvider: metadataProvider);
tagHelper.ViewContext.Html5DateRenderingMode = dateRenderingMode;
- var tagBuilder = new TagBuilder("input", new NullTestEncoder());
+ var tagBuilder = new TagBuilder("input");
htmlGenerator
.Setup(mock => mock.GenerateTextBox(
tagHelper.ViewContext,
@@ -895,9 +898,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.True(output.SelfClosing);
Assert.Equal(expectedAttributes, output.Attributes);
- Assert.Empty(output.PreContent);
- Assert.Equal(new[] { string.Empty }, output.Content);
- Assert.Empty(output.PostContent);
+ Assert.Empty(output.PreContent.GetContent());
+ Assert.Equal(string.Empty, output.Content.GetContent());
+ Assert.Empty(output.PostContent.GetContent());
Assert.Equal(expectedTagName, output.TagName);
}
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/LabelTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/LabelTagHelperTest.cs
index 80457002f4..4c61d8bddd 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/LabelTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/LabelTagHelperTest.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Xunit;
@@ -222,7 +223,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Assert
Assert.Equal(expectedAttributes, output.Attributes);
Assert.Equal(expectedPreContent, output.PreContent.GetContent());
- Assert.Equal(tagHelperOutputContent.ExpectedContent, output.Content.GetContent());
+ Assert.Equal(
+ tagHelperOutputContent.ExpectedContent,
+ HtmlContentUtilities.HtmlContentToString(output.Content));
Assert.Equal(expectedPostContent, output.PostContent.GetContent());
Assert.False(output.SelfClosing);
Assert.Equal(expectedTagName, output.TagName);
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs
index 7e2c843254..d2e1b90add 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs
@@ -8,6 +8,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Moq;
using Xunit;
@@ -334,7 +335,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal(expectedAttributes, output.Attributes);
Assert.Equal(expectedPreContent, output.PreContent.GetContent());
Assert.Equal(expectedContent, output.Content.GetContent());
- Assert.Equal(expectedPostContent, output.PostContent.GetContent());
+ Assert.Equal(expectedPostContent, HtmlContentUtilities.HtmlContentToString(output.PostContent));
Assert.Equal(expectedTagName, output.TagName);
Assert.NotNull(viewContext.FormContext?.FormData);
@@ -437,7 +438,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal(expectedAttributes, output.Attributes);
Assert.Equal(expectedPreContent, output.PreContent.GetContent());
Assert.Equal(expectedContent, output.Content.GetContent());
- Assert.Equal(expectedPostContent, output.PostContent.GetContent());
+ Assert.Equal(expectedPostContent, HtmlContentUtilities.HtmlContentToString(output.PostContent));
Assert.Equal(expectedTagName, output.TagName);
Assert.NotNull(viewContext.FormContext?.FormData);
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs
index a11060555a..78c60a0815 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs
@@ -425,7 +425,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Arrange
var tagHelperOutput = new TagHelperOutput("p", outputAttributes);
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
foreach (var attr in tagBuilderAttributes)
{
tagBuilder.Attributes.Add(attr.Key, attr.Value);
@@ -451,7 +451,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedAttribute = new TagHelperAttribute("type", "btn");
tagHelperOutput.Attributes.Add(expectedAttribute);
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
tagBuilder.Attributes.Add("type", "hello");
// Act
@@ -471,7 +471,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
attributes: new TagHelperAttributeList());
tagHelperOutput.Attributes.Add("class", "Hello");
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
tagBuilder.Attributes.Add("class", "btn");
var expectedAttribute = new TagHelperAttribute("class", "Hello btn");
@@ -497,7 +497,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
attributes: new TagHelperAttributeList());
tagHelperOutput.Attributes.Add(originalName, "Hello");
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
tagBuilder.Attributes.Add(updateName, "btn");
// Act
@@ -516,7 +516,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
"p",
attributes: new TagHelperAttributeList());
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
var expectedAttribute = new TagHelperAttribute("visible", "val < 3");
tagBuilder.Attributes.Add("visible", "val < 3");
@@ -536,7 +536,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
"p",
attributes: new TagHelperAttributeList());
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
var expectedAttribute1 = new TagHelperAttribute("class", "btn");
var expectedAttribute2 = new TagHelperAttribute("class2", "btn");
tagBuilder.Attributes.Add("class", "btn");
@@ -563,7 +563,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedAttribute = new TagHelperAttribute("class", "btn");
tagHelperOutput.Attributes.Add(expectedAttribute);
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
// Act
tagHelperOutput.MergeAttributes(tagBuilder);
@@ -583,7 +583,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var expectedOutputAttribute = new TagHelperAttribute("class", "btn");
tagHelperOutput.Attributes.Add(expectedOutputAttribute);
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
var expectedBuilderAttribute = new TagHelperAttribute("for", "hello");
tagBuilder.Attributes.Add("for", "hello");
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TestableHtmlGenerator.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TestableHtmlGenerator.cs
index 9cc7177b5b..1ab6d9efec 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TestableHtmlGenerator.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TestableHtmlGenerator.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO;
using Microsoft.AspNet.Antiforgery;
using Microsoft.AspNet.DataProtection;
+using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
@@ -70,9 +71,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
return viewContext;
}
- public override HtmlString GenerateAntiforgery(ViewContext viewContext)
+ public override IHtmlContent GenerateAntiforgery(ViewContext viewContext)
{
- var tagBuilder = new TagBuilder("input", new CommonTestEncoder())
+ var tagBuilder = new TagBuilder("input")
{
Attributes =
{
@@ -82,7 +83,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
},
};
- return tagBuilder.ToHtmlString(TagRenderMode.SelfClosing);
+ return tagBuilder.ToHtmlContent(TagRenderMode.SelfClosing);
}
protected override IDictionary GetValidationAttributes(
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TextAreaTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TextAreaTagHelperTest.cs
index e2b497f87b..3ec8d64303 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TextAreaTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TextAreaTagHelperTest.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Xunit;
@@ -46,32 +47,32 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
{ null, typeof(Model), null,
new NameAndId("Text", "Text"),
- Environment.NewLine + "HtmlEncode[[]]" },
+ Environment.NewLine },
{ modelWithNull, typeof(Model), modelWithNull.Text,
new NameAndId("Text", "Text"),
- Environment.NewLine + "HtmlEncode[[]]" },
+ Environment.NewLine },
{ modelWithText, typeof(Model), modelWithText.Text,
new NameAndId("Text", "Text"),
Environment.NewLine + "HtmlEncode[[outer text]]" },
{ modelWithNull, typeof(NestedModel), modelWithNull.NestedModel.Text,
new NameAndId("NestedModel.Text", "NestedModel_Text"),
- Environment.NewLine + "HtmlEncode[[]]" },
+ Environment.NewLine },
{ modelWithText, typeof(NestedModel), modelWithText.NestedModel.Text,
new NameAndId("NestedModel.Text", "NestedModel_Text"),
Environment.NewLine + "HtmlEncode[[inner text]]" },
{ models, typeof(Model), models[0].Text,
new NameAndId("[0].Text", "z0__Text"),
- Environment.NewLine + "HtmlEncode[[]]" },
+ Environment.NewLine },
{ models, typeof(Model), models[1].Text,
new NameAndId("[1].Text", "z1__Text"),
Environment.NewLine + "HtmlEncode[[outer text]]" },
{ models, typeof(NestedModel), models[0].NestedModel.Text,
new NameAndId("[0].NestedModel.Text", "z0__NestedModel_Text"),
- Environment.NewLine + "HtmlEncode[[]]" },
+ Environment.NewLine },
{ models, typeof(NestedModel), models[1].NestedModel.Text,
new NameAndId("[1].NestedModel.Text", "z1__NestedModel_Text"),
Environment.NewLine + "HtmlEncode[[inner text]]" },
@@ -151,7 +152,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Assert
Assert.True(output.SelfClosing);
Assert.Equal(expectedAttributes, output.Attributes);
- Assert.Equal(expectedContent, output.Content.GetContent());
+ Assert.Equal(expectedContent, HtmlContentUtilities.HtmlContentToString(output.Content));
Assert.Equal(expectedTagName, output.TagName);
}
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs
index bce90bd4bf..c95fdd1310 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs
@@ -93,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
generator
.Setup(mock =>
mock.GenerateValidationMessage(expectedViewContext, "Hello", null, null, null))
- .Returns(new TagBuilder("span", new CommonTestEncoder()))
+ .Returns(new TagBuilder("span"))
.Verifiable();
var validationMessageTagHelper = new ValidationMessageTagHelper(generator.Object)
@@ -142,9 +142,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
string childContent, string outputContent, string expectedOutputContent)
{
// Arrange
- var tagBuilder = new TagBuilder("span2", new CommonTestEncoder())
+ var tagBuilder = new TagBuilder("span2")
{
- InnerHtml = "New HTML"
+ InnerHtml = new HtmlString("New HTML")
};
tagBuilder.Attributes.Add("data-foo", "bar");
tagBuilder.Attributes.Add("data-hello", "world");
@@ -203,9 +203,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
string childContent, string expectedOutputContent)
{
// Arrange
- var tagBuilder = new TagBuilder("span2", new CommonTestEncoder())
+ var tagBuilder = new TagBuilder("span2")
{
- InnerHtml = "New HTML"
+ InnerHtml = new HtmlString("New HTML")
};
tagBuilder.Attributes.Add("data-foo", "bar");
tagBuilder.Attributes.Add("data-hello", "world");
diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs
index 104ec3ac48..c6df962541 100644
--- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs
+++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs
@@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
null, // message
null, // headerTag
null)) // htmlAttributes
- .Returns(new TagBuilder("div", new HtmlEncoder()))
+ .Returns(new TagBuilder("div"))
.Verifiable();
var validationSummaryTagHelper = new ValidationSummaryTagHelper(generator.Object)
@@ -130,9 +130,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
public async Task ProcessAsync_MergesTagBuilderFromGenerateValidationSummary()
{
// Arrange
- var tagBuilder = new TagBuilder("span2", new HtmlEncoder())
+ var tagBuilder = new TagBuilder("span2")
{
- InnerHtml = "New HTML"
+ InnerHtml = new HtmlString("New HTML")
};
tagBuilder.Attributes.Add("data-foo", "bar");
@@ -224,9 +224,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
public async Task ProcessAsync_GeneratesValidationSummaryWhenNotNone(ValidationSummary validationSummary)
{
// Arrange
- var tagBuilder = new TagBuilder("span2", new HtmlEncoder())
+ var tagBuilder = new TagBuilder("span2")
{
- InnerHtml = "New HTML"
+ InnerHtml = new HtmlString("New HTML")
};
var generator = new Mock();
diff --git a/test/Microsoft.AspNet.Mvc.TestCommon/HtmlContentUtilities.cs b/test/Microsoft.AspNet.Mvc.TestCommon/HtmlContentUtilities.cs
new file mode 100644
index 0000000000..5357dedbde
--- /dev/null
+++ b/test/Microsoft.AspNet.Mvc.TestCommon/HtmlContentUtilities.cs
@@ -0,0 +1,27 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.IO;
+using Microsoft.AspNet.Html.Abstractions;
+using Microsoft.Framework.WebEncoders;
+using Microsoft.Framework.WebEncoders.Testing;
+
+namespace Microsoft.AspNet.Mvc.TestCommon
+{
+ public class HtmlContentUtilities
+ {
+ public static string HtmlContentToString(IHtmlContent content, IHtmlEncoder encoder = null)
+ {
+ if (encoder == null)
+ {
+ encoder = new CommonTestEncoder();
+ }
+
+ using (var writer = new StringWriter())
+ {
+ content.WriteTo(writer, encoder);
+ return writer.ToString();
+ }
+ }
+ }
+}
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/BufferedHtmlContentTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/BufferedHtmlContentTest.cs
deleted file mode 100644
index 2597dfb7e4..0000000000
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/BufferedHtmlContentTest.cs
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.IO;
-using Microsoft.AspNet.Html.Abstractions;
-using Microsoft.Framework.WebEncoders;
-using Microsoft.Framework.WebEncoders.Testing;
-using Xunit;
-
-namespace Microsoft.AspNet.Mvc.Rendering
-{
- public class BufferedHtmlContentTest
- {
- [Fact]
- public void AppendString_AppendsAString()
- {
- // Arrange
- var content = new BufferedHtmlContent();
-
- // Act
- content.Append("Hello");
-
- // Assert
- var result = Assert.Single(content.Entries);
- Assert.IsType(typeof(string), result);
- }
-
- [Fact]
- public void AppendCharArray_AppendsAsString()
- {
- // Arrange
- var content = new BufferedHtmlContent();
-
- // Act
- content.Append(new char[] { 'h', 'e', 'l', 'l', 'o' }, 0, 5);
-
- // Assert
- var result = Assert.Single(content.Entries);
- Assert.IsType(typeof(string), result);
- }
-
- [Fact]
- public void AppendIHtmlContent_AppendsAsIs()
- {
- // Arrange
- var content = new BufferedHtmlContent();
- var writer = new StringWriter();
-
- // Act
- content.Append(new TestHtmlContent("Hello"));
-
- // Assert
- var result = Assert.Single(content.Entries);
- var testHtmlContent = Assert.IsType(result);
- testHtmlContent.WriteTo(writer, new CommonTestEncoder());
- Assert.Equal("Written from TestHtmlContent: Hello", writer.ToString());
- }
-
- [Fact]
- public void CanAppendMultipleItems()
- {
- // Arrange
- var content = new BufferedHtmlContent();
-
- // Act
- content.Append(new TestHtmlContent("hello"));
- content.Append("Test");
-
- // Assert
- Assert.Equal(2, content.Entries.Count);
- Assert.Equal("Written from TestHtmlContent: hello", content.Entries[0].ToString());
- Assert.Equal("Test", content.Entries[1]);
- }
-
- [Fact]
- public void Clear_DeletesAllItems()
- {
- // Arrange
- var content = new BufferedHtmlContent();
- content.Append(new TestHtmlContent("hello"));
- content.Append("Test");
-
- // Act
- content.Clear();
-
- // Assert
- Assert.Equal(0, content.Entries.Count);
- }
-
- [Fact]
- public void WriteTo_WritesAllItems()
- {
- // Arrange
- var content = new BufferedHtmlContent();
- var writer = new StringWriter();
- content.Append(new TestHtmlContent("Hello"));
- content.Append("Test");
-
- // Act
- content.WriteTo(writer, new CommonTestEncoder());
-
- // Assert
- Assert.Equal(2, content.Entries.Count);
- Assert.Equal("Written from TestHtmlContent: HelloTest", writer.ToString());
- }
-
- private class TestHtmlContent : IHtmlContent
- {
- private string _content;
-
- public TestHtmlContent(string content)
- {
- _content = content;
- }
-
- public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
- {
- writer.Write(ToString());
- }
-
- public override string ToString()
- {
- return "Written from TestHtmlContent: " + _content;
- }
- }
- }
-}
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultDisplayTemplatesTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultDisplayTemplatesTest.cs
index 68a887c027..aab174fbcd 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultDisplayTemplatesTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultDisplayTemplatesTest.cs
@@ -10,6 +10,7 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
+using Microsoft.AspNet.Mvc.TestCommon;
using Moq;
using Xunit;
@@ -63,7 +64,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultDisplayTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -82,7 +83,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultDisplayTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal("(null value)", result);
+ Assert.Equal("(null value)", HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -112,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultDisplayTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(expectedResult, result);
+ Assert.Equal(expectedResult, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -121,9 +122,9 @@ namespace Microsoft.AspNet.Mvc.Core
// Arrange
var expected =
@"HtmlEncode[[Property1]]
-HtmlEncode[[]]
+
HtmlEncode[[Property3]]
-HtmlEncode[[]]
+
";
var model = new DefaultTemplatesUtilities.ObjectWithScaffoldColumn();
var viewEngine = new Mock();
@@ -135,7 +136,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultDisplayTemplates.ObjectTemplate(htmlHelper);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -162,7 +163,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultDisplayTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -204,7 +205,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultDisplayTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -223,7 +224,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultDisplayTemplates.HiddenInputTemplate(html);
// Assert
- Assert.Equal("HtmlEncode[[Formatted string]]", result);
+ Assert.Equal("HtmlEncode[[Formatted string]]", HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -249,7 +250,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultDisplayTemplates.HiddenInputTemplate(html);
// Assert
- Assert.Empty(result);
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -268,7 +269,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = helper.Display("Property1");
// Assert
- Assert.Equal("HtmlEncode[[ViewData string]]", result.ToString());
+ Assert.Equal("HtmlEncode[[ViewData string]]", HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -287,7 +288,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = helper.DisplayFor(m => m.Property1);
// Assert
- Assert.Equal("HtmlEncode[[Model string]]", result.ToString());
+ Assert.Equal("HtmlEncode[[Model string]]", HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -305,7 +306,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = helper.Display("Property1");
// Assert
- Assert.Equal("HtmlEncode[[Model string]]", result.ToString());
+ Assert.Equal("HtmlEncode[[Model string]]", HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -326,7 +327,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = helper.DisplayFor(m => m.Property1);
// Assert
- Assert.Equal("HtmlEncode[[]]", result.ToString());
+ Assert.Equal(string.Empty, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultEditorTemplatesTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultEditorTemplatesTest.cs
index 1a8d5a5c1c..235ecf76f2 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultEditorTemplatesTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultEditorTemplatesTest.cs
@@ -14,6 +14,7 @@ using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.Rendering.Internal;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
@@ -111,7 +112,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultEditorTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -134,7 +135,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultEditorTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(html.ViewData.ModelMetadata.NullDisplayText, result);
+ Assert.Equal(html.ViewData.ModelMetadata.NullDisplayText, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -167,7 +168,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = DefaultEditorTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(expectedResult, result);
+ Assert.Equal(expectedResult, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -196,7 +197,7 @@ Environment.NewLine;
var result = DefaultEditorTemplates.ObjectTemplate(htmlHelper);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -226,7 +227,7 @@ Environment.NewLine;
var result = DefaultEditorTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -270,7 +271,7 @@ Environment.NewLine;
var result = DefaultEditorTemplates.ObjectTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -292,7 +293,7 @@ Environment.NewLine;
var result = DefaultEditorTemplates.HiddenInputTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -319,7 +320,7 @@ Environment.NewLine;
var result = DefaultEditorTemplates.HiddenInputTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -343,7 +344,7 @@ Environment.NewLine;
var result = DefaultEditorTemplates.MultilineTemplate(html);
// Assert
- Assert.Equal(expected, result);
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -373,7 +374,7 @@ Environment.NewLine;
additionalViewData: null);
// Assert
- Assert.Equal(expectedResult, result.ToString());
+ Assert.Equal(expectedResult, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -402,7 +403,7 @@ Environment.NewLine;
additionalViewData: null);
// Assert
- Assert.Equal(expectedResult, result.ToString());
+ Assert.Equal(expectedResult, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -441,7 +442,7 @@ Environment.NewLine;
additionalViewData: null);
// Assert
- Assert.Equal(expectedResult, result.ToString());
+ Assert.Equal(expectedResult, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -479,7 +480,7 @@ Environment.NewLine;
additionalViewData: null);
// Assert
- Assert.Equal(expectedResult, result.ToString());
+ Assert.Equal(expectedResult, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -518,7 +519,7 @@ Environment.NewLine;
additionalViewData: null);
// Assert
- Assert.Equal(expectedResult, result.ToString());
+ Assert.Equal(expectedResult, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -556,7 +557,7 @@ Environment.NewLine;
additionalViewData: null);
// Assert
- Assert.Equal(expectedResult, result.ToString());
+ Assert.Equal(expectedResult, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -577,7 +578,7 @@ Environment.NewLine;
// Assert
Assert.Equal(
" ",
- result.ToString());
+ HtmlContentUtilities.HtmlContentToString(result));
}
// DateTime-local is not special-cased unless using Html5DateRenderingMode.Rfc3339.
@@ -631,7 +632,7 @@ Environment.NewLine;
var result = helper.Editor("");
// Assert
- Assert.Equal(expectedInput, result.ToString());
+ Assert.Equal(expectedInput, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -686,7 +687,7 @@ Environment.NewLine;
var result = helper.Editor("");
// Assert
- Assert.Equal(expectedInput, result.ToString());
+ Assert.Equal(expectedInput, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -746,7 +747,7 @@ Environment.NewLine;
var result = helper.Editor("");
// Assert
- Assert.Equal(expectedInput, result.ToString());
+ Assert.Equal(expectedInput, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -767,7 +768,7 @@ Environment.NewLine;
// Assert
Assert.Equal(
" ",
- result.ToString());
+ HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -787,7 +788,7 @@ Environment.NewLine;
// Assert
Assert.Equal(
" ",
- result.ToString());
+ HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -810,7 +811,7 @@ Environment.NewLine;
// Assert
Assert.Equal(
" ",
- result.ToString());
+ HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -917,11 +918,6 @@ Environment.NewLine;
get { return _innerHelper.TempData; }
}
- public IHtmlEncoder HtmlEncoder
- {
- get { return _innerHelper.HtmlEncoder; }
- }
-
public IUrlEncoder UrlEncoder
{
get { return _innerHelper.UrlEncoder; }
@@ -937,7 +933,7 @@ Environment.NewLine;
(_innerHelper as ICanHasViewContext)?.Contextualize(viewContext);
}
- public HtmlString ActionLink(
+ public IHtmlContent ActionLink(
[NotNull] string linkText,
string actionName,
string controllerName,
@@ -950,7 +946,7 @@ Environment.NewLine;
throw new NotImplementedException();
}
- public HtmlString AntiForgeryToken()
+ public IHtmlContent AntiForgeryToken()
{
throw new NotImplementedException();
}
@@ -974,12 +970,12 @@ Environment.NewLine;
throw new NotImplementedException();
}
- public HtmlString CheckBox(string name, bool? isChecked, object htmlAttributes)
+ public IHtmlContent CheckBox(string name, bool? isChecked, object htmlAttributes)
{
return HelperName("__CheckBox__", htmlAttributes);
}
- public HtmlString Display(
+ public IHtmlContent Display(
string expression,
string templateName,
string htmlFieldName,
@@ -998,7 +994,7 @@ Environment.NewLine;
throw new NotImplementedException();
}
- public HtmlString DropDownList(
+ public IHtmlContent DropDownList(
string name,
IEnumerable selectList,
string optionLabel,
@@ -1007,7 +1003,7 @@ Environment.NewLine;
return HelperName("__DropDownList__", htmlAttributes);
}
- public HtmlString Editor(
+ public IHtmlContent Editor(
string expression,
string templateName,
string htmlFieldName,
@@ -1058,7 +1054,7 @@ Environment.NewLine;
throw new NotImplementedException();
}
- public HtmlString Hidden(string name, object value, object htmlAttributes)
+ public IHtmlContent Hidden(string name, object value, object htmlAttributes)
{
return HelperName("__Hidden__", htmlAttributes);
}
@@ -1068,12 +1064,12 @@ Environment.NewLine;
throw new NotImplementedException();
}
- public HtmlString Label(string expression, string labelText, object htmlAttributes)
+ public IHtmlContent Label(string expression, string labelText, object htmlAttributes)
{
return HelperName("__Label__", htmlAttributes);
}
- public HtmlString ListBox(string name, IEnumerable selectList, object htmlAttributes)
+ public IHtmlContent ListBox(string name, IEnumerable selectList, object htmlAttributes)
{
throw new NotImplementedException();
}
@@ -1091,22 +1087,22 @@ Environment.NewLine;
throw new NotImplementedException();
}
- public HtmlString Password(string name, object value, object htmlAttributes)
+ public IHtmlContent Password(string name, object value, object htmlAttributes)
{
return HelperName("__Password__", htmlAttributes);
}
- public HtmlString RadioButton(string name, object value, bool? isChecked, object htmlAttributes)
+ public IHtmlContent RadioButton(string name, object value, bool? isChecked, object htmlAttributes)
{
return HelperName("__RadioButton__", htmlAttributes);
}
- public HtmlString Raw(object value)
+ public IHtmlContent Raw(object value)
{
throw new NotImplementedException();
}
- public HtmlString Raw(string value)
+ public IHtmlContent Raw(string value)
{
throw new NotImplementedException();
}
@@ -1116,7 +1112,7 @@ Environment.NewLine;
throw new NotImplementedException();
}
- public HtmlString RouteLink(
+ public IHtmlContent RouteLink(
[NotNull] string linkText,
string routeName,
string protocol,
@@ -1128,22 +1124,22 @@ Environment.NewLine;
throw new NotImplementedException();
}
- public HtmlString TextArea(string name, string value, int rows, int columns, object htmlAttributes)
+ public IHtmlContent TextArea(string name, string value, int rows, int columns, object htmlAttributes)
{
return HelperName("__TextArea__", htmlAttributes);
}
- public HtmlString TextBox(string name, object value, string format, object htmlAttributes)
+ public IHtmlContent TextBox(string name, object value, string format, object htmlAttributes)
{
return HelperName("__TextBox__", htmlAttributes);
}
- public HtmlString ValidationMessage(string modelName, string message, object htmlAttributes, string tag)
+ public IHtmlContent ValidationMessage(string modelName, string message, object htmlAttributes, string tag)
{
return HelperName("__ValidationMessage__", htmlAttributes);
}
- public HtmlString ValidationSummary(
+ public IHtmlContent ValidationSummary(
bool excludePropertyErrors,
string message,
object htmlAttributes,
@@ -1157,7 +1153,7 @@ Environment.NewLine;
throw new NotImplementedException();
}
- private HtmlString HelperName(string name, object htmlAttributes)
+ private IHtmlContent HelperName(string name, object htmlAttributes)
{
var htmlAttributesDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
var htmlAttributesString =
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperCheckboxTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperCheckboxTest.cs
index a352f5bcd4..c0816f83b3 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperCheckboxTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperCheckboxTest.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Microsoft.AspNet.Mvc.ModelBinding;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Routing;
using Xunit;
@@ -31,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: new { @checked = "checked", value = "false" });
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: new { @checked = "unchecked", value = "false" });
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -70,7 +71,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: new { @checked = "unchecked", value = "false" });
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -121,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: true, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -141,7 +142,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -160,7 +161,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -182,7 +183,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -203,7 +204,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Prefix.Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -225,7 +226,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -245,7 +246,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -266,7 +267,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -285,7 +286,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -305,7 +306,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -323,7 +324,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Name", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -344,7 +345,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: true, htmlAttributes: htmlAttributes);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -362,7 +363,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: false, htmlAttributes: dictionary);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -382,7 +383,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("Property1", isChecked: false, htmlAttributes: dictionary);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -403,7 +404,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox(string.Empty, isChecked: false, htmlAttributes: attributes);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -423,7 +424,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBox("ComplexProperty.Property1", isChecked: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -444,7 +445,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Theory]
@@ -472,7 +473,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -491,7 +492,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.Property3, new { @checked = "checked", value = "false" });
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -514,7 +515,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.Name, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Theory]
@@ -540,7 +541,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -560,7 +561,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.Property1, htmlAttributes);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -580,7 +581,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.Property1, attributes);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -601,7 +602,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.Property1, attributes);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -620,7 +621,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.CheckBoxFor(m => m.ComplexProperty.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
private static ViewDataDictionary GetTestModelViewData()
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperFormExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperFormExtensionsTest.cs
index bbdf59e88d..923688aad4 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperFormExtensionsTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperFormExtensionsTest.cs
@@ -276,7 +276,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public void BeginFormWithNoParameters_CallsHtmlGeneratorWithExpectedValues()
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -310,7 +310,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public void BeginFormWithMethodParameter_CallsHtmlGeneratorWithExpectedValues(FormMethod method)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -346,7 +346,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
object htmlAttributes)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -380,7 +380,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public void BeginFormWithRouteValuesParameter_CallsHtmlGeneratorWithExpectedValues(object routeValues)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -416,7 +416,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
string controllerName)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -453,7 +453,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
object routeValues)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -490,7 +490,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
FormMethod method)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -528,7 +528,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
FormMethod method)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -566,7 +566,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
object htmlAttributes)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -600,7 +600,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public void BeginRouteFormWithRouteValuesParameter_CallsHtmlGeneratorWithExpectedValues(object routeValues)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -633,7 +633,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public void BeginRouteFormWithRouteNameParameter_CallsHtmlGeneratorWithExpectedValues(string routeName)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -668,7 +668,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
object routeValues)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -703,7 +703,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
FormMethod method)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -739,7 +739,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
FormMethod method)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
@@ -775,7 +775,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
object htmlAttributes)
{
// Arrange
- var tagBuilder = new TagBuilder(tagName: "form", htmlEncoder: new NullTestEncoder());
+ var tagBuilder = new TagBuilder(tagName: "form");
var htmlGenerator = new Mock(MockBehavior.Strict);
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(htmlGenerator.Object);
htmlGenerator
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperHiddenTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperHiddenTest.cs
index 34825ec401..2be4e6818b 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperHiddenTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperHiddenTest.cs
@@ -7,6 +7,7 @@ using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq.Expressions;
using Microsoft.AspNet.Mvc.ModelBinding;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Testing;
using Xunit;
@@ -41,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("ProductName", new byte[] { 23, 43, 53 }, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -56,7 +57,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", "test", attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -73,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.Hidden("Prefix.Property1", value: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -91,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.Hidden("Property1", value: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -108,7 +109,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.Hidden("Property1", value: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -126,7 +127,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.Hidden("Property1", value: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -142,7 +143,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", "explicit-value", attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -158,7 +159,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", "test", attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -174,7 +175,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", "test", attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -189,7 +190,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", value: "explicit-value", htmlAttributes: new { value = "attribute-value" });
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -205,7 +206,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", value: "explicit-value", htmlAttributes: new { value = "attribute-value" });
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -221,7 +222,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", value: null, htmlAttributes: new { value = "attribute-value" });
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -236,7 +237,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", value: null, htmlAttributes: new { value = "attribute-value" });
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -253,7 +254,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.Hidden("Property1", value: null, htmlAttributes: new { value = "attribute-value" });
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -267,7 +268,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", value: null, htmlAttributes: new { value = "attribute-value" });
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -283,7 +284,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.Hidden("Property1", value: null, htmlAttributes: new { value = "attribute-value" });
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -299,7 +300,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("keyNotFound", value: null, htmlAttributes: attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -315,7 +316,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.Hidden("keyNotFound", value: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, html.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -331,7 +332,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", "PropValue", htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -346,7 +347,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden(string.Empty, "fooValue", htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -368,7 +369,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", "explicit-value", htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -391,7 +392,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", value: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -432,7 +433,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property1", value: null, htmlAttributes: attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -449,7 +450,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden("Property2", value: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
public static IEnumerable HiddenWithComplexExpressions_UsesValueFromViewDataData
@@ -495,7 +496,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden(expression, value: null, htmlAttributes: attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
public static IEnumerable HiddenWithComplexExpressions_UsesIdDotSeparatorData
@@ -534,7 +535,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Hidden(expression, value: null, htmlAttributes: attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -549,7 +550,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Bytes, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -564,7 +565,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, htmlAttributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -579,7 +580,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -595,7 +596,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -611,7 +612,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -626,7 +627,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
// This test ensures that specifying a the prefix does not affect the expression result.
@@ -644,7 +645,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -667,7 +668,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -687,7 +688,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -704,7 +705,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property2, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
public static TheoryData HiddenFor_UsesPropertyValueIfModelStateDoesNotContainValueData
@@ -765,7 +766,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(expression, attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
public static TheoryData HiddenFor_UsesModelStateValueForComplexExpressionsData
@@ -813,7 +814,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(expression, attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -831,7 +832,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.HiddenFor(m => m.Property1, attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
private static ViewDataDictionary GetViewDataWithNullModelAndNonNullViewData()
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperLabelExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperLabelExtensionsTest.cs
index 456445a423..d0dc9570ef 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperLabelExtensionsTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperLabelExtensionsTest.cs
@@ -4,6 +4,7 @@
using System;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
+using Microsoft.AspNet.Mvc.TestCommon;
using Xunit;
namespace Microsoft.AspNet.Mvc.Core
@@ -26,10 +27,10 @@ namespace Microsoft.AspNet.Mvc.Core
var labelForModelResult = helper.LabelForModel();
// Assert
- Assert.Empty(labelResult.ToString());
- Assert.Empty(labelNullResult.ToString());
- Assert.Empty(labelForResult.ToString());
- Assert.Empty(labelForModelResult.ToString());
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelNullResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelForResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelForModelResult));
}
[Fact]
@@ -43,8 +44,8 @@ namespace Microsoft.AspNet.Mvc.Core
var labelForResult = helper.LabelFor(m => m.Property1);
// Assert
- Assert.Equal("HtmlEncode[[Property1]] ", labelResult.ToString());
- Assert.Equal("HtmlEncode[[Property1]] ", labelForResult.ToString());
+ Assert.Equal("HtmlEncode[[Property1]] ", HtmlContentUtilities.HtmlContentToString(labelResult));
+ Assert.Equal("HtmlEncode[[Property1]] ", HtmlContentUtilities.HtmlContentToString(labelForResult));
}
[Fact]
@@ -58,8 +59,8 @@ namespace Microsoft.AspNet.Mvc.Core
var labelForResult = helper.LabelFor(m => m.Inner.Id);
// Assert
- Assert.Equal("HtmlEncode[[Id]] ", labelResult.ToString());
- Assert.Equal("HtmlEncode[[Id]] ", labelForResult.ToString());
+ Assert.Equal("HtmlEncode[[Id]] ", HtmlContentUtilities.HtmlContentToString(labelResult));
+ Assert.Equal("HtmlEncode[[Id]] ", HtmlContentUtilities.HtmlContentToString(labelForResult));
}
[Fact]
@@ -83,9 +84,9 @@ namespace Microsoft.AspNet.Mvc.Core
var labelForModelResult = helper.LabelForModel();
// Assert
- Assert.Equal("HtmlEncode[[" + propertyName + "]] ", labelResult.ToString());
- Assert.Equal("HtmlEncode[[" + propertyName + "]] ", labelForResult.ToString());
- Assert.Equal("HtmlEncode[[" + propertyName + "]] ", labelForModelResult.ToString());
+ Assert.Equal("HtmlEncode[[" + propertyName + "]] ", HtmlContentUtilities.HtmlContentToString(labelResult));
+ Assert.Equal("HtmlEncode[[" + propertyName + "]] ", HtmlContentUtilities.HtmlContentToString(labelForResult));
+ Assert.Equal("HtmlEncode[[" + propertyName + "]] ", HtmlContentUtilities.HtmlContentToString(labelForModelResult));
}
// If the metadata is for a type (not property), then Label(expression) will evaluate the expression
@@ -100,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.Core
var labelResult = helper.Label(expression: "value");
// Assert
- Assert.Equal("HtmlEncode[[value]] ", labelResult.ToString());
+ Assert.Equal("HtmlEncode[[value]] ", HtmlContentUtilities.HtmlContentToString(labelResult));
}
[Fact]
@@ -121,10 +122,10 @@ namespace Microsoft.AspNet.Mvc.Core
var labelForModelResult = helper.LabelForModel();
// Assert
- Assert.Empty(labelResult.ToString());
- Assert.Empty(labelNullResult.ToString());
- Assert.Empty(labelForResult.ToString());
- Assert.Empty(labelForModelResult.ToString());
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelNullResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelForResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelForModelResult));
}
[Theory]
@@ -146,9 +147,9 @@ namespace Microsoft.AspNet.Mvc.Core
var labelForModelResult = helper.LabelForModel();
// Assert
- Assert.Equal("HtmlEncode[[" + displayName + "]] ", labelResult.ToString());
- Assert.Equal("HtmlEncode[[" + displayName + "]] ", labelForResult.ToString());
- Assert.Equal("HtmlEncode[[" + displayName + "]] ", labelForModelResult.ToString());
+ Assert.Equal("HtmlEncode[[" + displayName + "]] ", HtmlContentUtilities.HtmlContentToString(labelResult));
+ Assert.Equal("HtmlEncode[[" + displayName + "]] ", HtmlContentUtilities.HtmlContentToString(labelForResult));
+ Assert.Equal("HtmlEncode[[" + displayName + "]] ", HtmlContentUtilities.HtmlContentToString(labelForModelResult));
}
[Fact]
@@ -173,10 +174,10 @@ namespace Microsoft.AspNet.Mvc.Core
var labelForModelResult = helper.LabelForModel();
// Assert
- Assert.Empty(labelResult.ToString());
- Assert.Empty(labelNullResult.ToString());
- Assert.Empty(labelForResult.ToString());
- Assert.Empty(labelForModelResult.ToString());
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelNullResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelForResult));
+ Assert.Empty(HtmlContentUtilities.HtmlContentToString(labelForModelResult));
}
[Theory]
@@ -197,8 +198,8 @@ namespace Microsoft.AspNet.Mvc.Core
var labelForResult = helper.LabelFor(m => m.Property1);
// Assert
- Assert.Equal("HtmlEncode[[" + displayName + "]] ", labelResult.ToString());
- Assert.Equal("HtmlEncode[[" + displayName + "]] ", labelForResult.ToString());
+ Assert.Equal("HtmlEncode[[" + displayName + "]] ", HtmlContentUtilities.HtmlContentToString(labelResult));
+ Assert.Equal("HtmlEncode[[" + displayName + "]] ", HtmlContentUtilities.HtmlContentToString(labelForResult));
}
[Theory]
@@ -219,7 +220,7 @@ namespace Microsoft.AspNet.Mvc.Core
// Assert
// Label() falls back to expression name when DisplayName and PropertyName are null.
- Assert.Equal("HtmlEncode[[" + expectedText + "]] ", result.ToString());
+ Assert.Equal("HtmlEncode[[" + expectedText + "]] ", HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -247,7 +248,7 @@ namespace Microsoft.AspNet.Mvc.Core
var result = helper.LabelFor(model => unknownKey);
// Assert
- Assert.Equal("HtmlEncode[[unknownKey]] ", result.ToString());
+ Assert.Equal("HtmlEncode[[unknownKey]] ", HtmlContentUtilities.HtmlContentToString(result));
}
private sealed class InnerClass
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperLinkGenerationTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperLinkGenerationTest.cs
index 0f71064e5c..61f77a75d9 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperLinkGenerationTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperLinkGenerationTest.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.Framework.Internal;
using Moq;
using Xunit;
@@ -78,10 +79,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
hostname: hostname,
fragment: fragment,
routeValues: routeValues,
- htmlAttributes: htmlAttributes).ToString();
+ htmlAttributes: htmlAttributes);
// Assert
- Assert.Equal(expectedLink, actualLink);
+ Assert.Equal(expectedLink, HtmlContentUtilities.HtmlContentToString(actualLink));
}
public static IEnumerable RouteLinkGenerationData
@@ -141,10 +142,10 @@ namespace Microsoft.AspNet.Mvc.Rendering
hostName: hostname,
fragment: fragment,
routeValues: routeValues,
- htmlAttributes: htmlAttributes).ToString();
+ htmlAttributes: htmlAttributes);
// Assert
- Assert.Equal(expectedLink, actualLink);
+ Assert.Equal(expectedLink, HtmlContentUtilities.HtmlContentToString(actualLink));
}
private string GetRouteValuesAsString(object routeValues)
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPasswordTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPasswordTest.cs
index 450560a915..48d187f0de 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPasswordTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPasswordTest.cs
@@ -7,6 +7,7 @@ using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq.Expressions;
using Microsoft.AspNet.Mvc.ModelBinding;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Testing;
using Xunit;
@@ -51,7 +52,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Password("Property1", value: null, htmlAttributes: attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -68,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Password("Property1", "explicit-value", attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -84,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Password("Property1", "explicit-value", htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -102,7 +103,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Password("Property1", "explicit-value", htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -118,7 +119,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Password(name, "explicit-value", htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -159,7 +160,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Password("Property1", value: null, htmlAttributes: attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -176,7 +177,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Password("Property2", value: null, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
public static IEnumerable PasswordWithComplexExpressions_UsesIdDotSeparatorData
@@ -212,7 +213,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.Password(expression, value: null, htmlAttributes: attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -230,7 +231,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.PasswordFor(m => m.Property1, htmlAttributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -245,7 +246,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.PasswordFor(m => m.Property1, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -267,7 +268,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.PasswordFor(m => m.Property1, attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -284,7 +285,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.PasswordFor(m => m.Property2, htmlAttributes: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
public static TheoryData PasswordFor_WithComplexExpressionsData
@@ -338,7 +339,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var result = helper.PasswordFor(expression, attributes);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
private static ViewDataDictionary GetViewDataWithNullModelAndNonEmptyViewData()
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperSelectTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperSelectTest.cs
index dee880a29d..689daf0a9e 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperSelectTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperSelectTest.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Microsoft.AspNet.Mvc.ModelBinding;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
@@ -334,7 +335,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", selectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedDisabled, selectList.Select(item => item.Disabled));
Assert.Equal(savedGroup, selectList.Select(item => item.Group));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
@@ -358,7 +359,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", selectList: null, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -399,7 +400,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", selectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -439,7 +440,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", SourcesSelectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -481,7 +482,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", SourcesSelectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -506,7 +507,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", SourcesSelectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -534,7 +535,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", SourcesSelectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -561,7 +562,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", SourcesSelectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -577,7 +578,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", SourcesSelectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -594,7 +595,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownList("Property1", SourcesSelectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Theory]
@@ -616,7 +617,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -640,7 +641,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -664,7 +665,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -689,7 +690,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -717,7 +718,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -740,7 +741,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownListFor(value => unrelated, selectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -764,7 +765,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedDisabled, selectList.Select(item => item.Disabled));
Assert.Equal(savedGroup, selectList.Select(item => item.Group));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
@@ -789,7 +790,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -810,7 +811,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -850,7 +851,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", SourcesSelectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -892,7 +893,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", SourcesSelectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -917,7 +918,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", SourcesSelectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -945,7 +946,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", SourcesSelectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -972,7 +973,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", SourcesSelectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -988,7 +989,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", SourcesSelectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Fact]
@@ -1005,7 +1006,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox("Property1", SourcesSelectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
}
[Theory]
@@ -1024,7 +1025,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBoxFor(value => value.Property1, selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1045,7 +1046,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBoxFor(value => value.Property1, selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1069,7 +1070,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBoxFor(value => unrelated, selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1090,7 +1091,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBoxFor(value => value.Property1, selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1118,7 +1119,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedDisabled, selectList.Select(item => item.Disabled));
Assert.Equal(savedGroup, selectList.Select(item => item.Group));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
@@ -1146,7 +1147,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1166,7 +1167,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownListFor(value => value, selectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1186,7 +1187,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.DropDownListFor(value => value, selectList, optionLabel: null, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1211,7 +1212,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox(expression: string.Empty, selectList: selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedDisabled, selectList.Select(item => item.Disabled));
Assert.Equal(savedGroup, selectList.Select(item => item.Group));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
@@ -1237,7 +1238,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBox(expression: string.Empty, selectList: selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1258,7 +1259,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBoxFor(value => value, selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
@@ -1280,7 +1281,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var html = helper.ListBoxFor(value => value, selectList, htmlAttributes: null);
// Assert
- Assert.Equal(expectedHtml, html.ToString());
+ Assert.Equal(expectedHtml, HtmlContentUtilities.HtmlContentToString(html));
Assert.Equal(savedSelected, selectList.Select(item => item.Selected));
}
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperValidationSummaryTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperValidationSummaryTest.cs
index 42e68c80b4..bb67cf4404 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperValidationSummaryTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperValidationSummaryTest.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Mvc.ModelBinding;
+using Microsoft.AspNet.Mvc.TestCommon;
using Xunit;
namespace Microsoft.AspNet.Mvc.Rendering
@@ -150,7 +151,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
tag: tag);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -222,7 +223,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
tag: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -248,7 +249,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
tag: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -273,7 +274,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
tag: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Theory]
@@ -297,7 +298,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
tag: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
[Fact]
@@ -330,7 +331,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
tag: null);
// Assert
- Assert.Equal(expected, result.ToString());
+ Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(result));
}
// Adds errors for various parts of the model, including the root.
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/StringCollectionTextWriterTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/StringCollectionTextWriterTest.cs
index 07b0ad98bb..90d6b743b8 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/StringCollectionTextWriterTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/StringCollectionTextWriterTest.cs
@@ -7,6 +7,7 @@ using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Testing;
+using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders.Testing;
using Xunit;
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/StringHtmlContentTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/StringHtmlContentTest.cs
new file mode 100644
index 0000000000..a5c4723aaa
--- /dev/null
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/StringHtmlContentTest.cs
@@ -0,0 +1,46 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.IO;
+using Microsoft.Framework.WebEncoders.Testing;
+using Xunit;
+
+namespace Microsoft.AspNet.Mvc.Rendering
+{
+ public class StringHtmlContentTest
+ {
+ [Fact]
+ public void ToString_ReturnsAString()
+ {
+ // Arrange & Act
+ var content = new StringHtmlContent("Hello World");
+
+ // Assert
+ Assert.Equal("Hello World", content.ToString());
+ }
+
+ [Fact]
+ public void ToString_ReturnsNullForNullInput()
+ {
+ // Arrange & Act
+ var content = new StringHtmlContent(null);
+
+ // Assert
+ Assert.Null(content.ToString());
+ }
+
+ [Fact]
+ public void WriteTo_WritesContent()
+ {
+ // Arrange & Act
+ var content = new StringHtmlContent("Hello World");
+
+ // Assert
+ using (var writer = new StringWriter())
+ {
+ content.WriteTo(writer, new CommonTestEncoder());
+ Assert.Equal("HtmlEncode[[Hello World]]", writer.ToString());
+ }
+ }
+ }
+}
diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/TagBuilderTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/TagBuilderTest.cs
index 429e3b43bc..280af2849a 100644
--- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/TagBuilderTest.cs
+++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/TagBuilderTest.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Rendering;
+using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.Framework.WebEncoders.Testing;
using Xunit;
@@ -29,7 +30,7 @@ namespace Microsoft.AspNet.Mvc.Core.Rendering
public void MergeAttribute_IgnoresCase(bool replaceExisting, string expectedKey, string expectedValue)
{
// Arrange
- var tagBuilder = new TagBuilder("p", new NullTestEncoder());
+ var tagBuilder = new TagBuilder("p");
tagBuilder.Attributes.Add("Hello", "World");
// Act
@@ -44,7 +45,7 @@ namespace Microsoft.AspNet.Mvc.Core.Rendering
public void AddCssClass_IgnoresCase()
{
// Arrange
- var tagBuilder = new TagBuilder("p", new NullTestEncoder());
+ var tagBuilder = new TagBuilder("p");
tagBuilder.Attributes.Add("ClaSs", "btn");
// Act
@@ -59,7 +60,7 @@ namespace Microsoft.AspNet.Mvc.Core.Rendering
public void GenerateId_IgnoresCase()
{
// Arrange
- var tagBuilder = new TagBuilder("p", new NullTestEncoder());
+ var tagBuilder = new TagBuilder("p");
tagBuilder.Attributes.Add("ID", "something");
// Act
@@ -75,16 +76,16 @@ namespace Microsoft.AspNet.Mvc.Core.Rendering
public void ToString_IgnoresIdAttributeCase(TagRenderMode renderingMode, string expectedOutput)
{
// Arrange
- var tagBuilder = new TagBuilder("p", new NullTestEncoder());
+ var tagBuilder = new TagBuilder("p");
// An empty value id attribute should not be rendered via ToString.
tagBuilder.Attributes.Add("ID", string.Empty);
// Act
- var value = tagBuilder.ToString(renderingMode);
+ var value = tagBuilder.ToHtmlContent(renderingMode);
// Assert
- Assert.Equal(expectedOutput, value);
+ Assert.Equal(expectedOutput, HtmlContentUtilities.HtmlContentToString(value, new NullTestEncoder()));
}
[Theory]
@@ -92,29 +93,31 @@ namespace Microsoft.AspNet.Mvc.Core.Rendering
public void ToHtmlString_IgnoresIdAttributeCase(TagRenderMode renderingMode, string expectedOutput)
{
// Arrange
- var tagBuilder = new TagBuilder("p", new NullTestEncoder());
+ var tagBuilder = new TagBuilder("p");
// An empty value id attribute should not be rendered via ToHtmlString.
tagBuilder.Attributes.Add("ID", string.Empty);
// Act
- var value = tagBuilder.ToHtmlString(renderingMode);
+ var value = tagBuilder.ToHtmlContent(renderingMode);
// Assert
- Assert.Equal(expectedOutput, value.ToString());
+ Assert.Equal(expectedOutput, HtmlContentUtilities.HtmlContentToString(value, new NullTestEncoder()));
}
[Fact]
public void SetInnerText_HtmlEncodesValue()
{
// Arrange
- var tagBuilder = new TagBuilder("p", new CommonTestEncoder());
+ var tagBuilder = new TagBuilder("p");
// Act
tagBuilder.SetInnerText("TestValue");
// Assert
- Assert.Equal("HtmlEncode[[TestValue]]", tagBuilder.InnerHtml);
+ Assert.Equal(
+ "HtmlEncode[[TestValue]]",
+ HtmlContentUtilities.HtmlContentToString(tagBuilder.InnerHtml));
}
[Theory]
diff --git a/test/WebSites/ActivatorWebSite/TagHelpers/TitleTagHelper.cs b/test/WebSites/ActivatorWebSite/TagHelpers/TitleTagHelper.cs
index 865dc83fe5..c7e1fbf96f 100644
--- a/test/WebSites/ActivatorWebSite/TagHelpers/TitleTagHelper.cs
+++ b/test/WebSites/ActivatorWebSite/TagHelpers/TitleTagHelper.cs
@@ -25,10 +25,10 @@ namespace ActivatorWebSite.TagHelpers
{
(HtmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);
- var builder = new TagBuilder("h2", HtmlHelper.HtmlEncoder);
+ var builder = new TagBuilder("h2");
var title = ViewContext.ViewBag.Title;
- builder.InnerHtml = HtmlHelper.Encode(title);
- output.PreContent.SetContent(builder.ToString());
+ builder.SetInnerText(title);
+ output.PreContent.SetContent(builder.ToHtmlContent(TagRenderMode.Normal));
}
}
}
\ No newline at end of file