diff --git a/src/MusicStore.Spa/Helpers/AngularExtensions.cs b/src/MusicStore.Spa/Helpers/AngularExtensions.cs index ea35dfb9fc..c633529853 100644 --- a/src/MusicStore.Spa/Helpers/AngularExtensions.cs +++ b/src/MusicStore.Spa/Helpers/AngularExtensions.cs @@ -5,39 +5,40 @@ using System.Linq; using System.Linq.Expressions; using Microsoft.AspNet.Mvc.Rendering.Expressions; using Microsoft.AspNet.Routing; +using Microsoft.AspNet.Html.Abstractions; namespace Microsoft.AspNet.Mvc.Rendering { public static class AngularExtensions { - public static HtmlString ngPasswordFor(this IHtmlHelper html, Expression> expression) + public static IHtmlContent ngPasswordFor(this IHtmlHelper html, Expression> expression) { return html.ngPasswordFor(expression, null); } - public static HtmlString ngPasswordFor(this IHtmlHelper html, Expression> expression, object htmlAttributes) + public static IHtmlContent ngPasswordFor(this IHtmlHelper html, Expression> expression, object htmlAttributes) { return html.ngPasswordFor(expression, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } - public static HtmlString ngPasswordFor(this IHtmlHelper html, Expression> expression, IDictionary htmlAttributes) + public static IHtmlContent ngPasswordFor(this IHtmlHelper html, Expression> expression, IDictionary htmlAttributes) { return html.ngTextBoxFor(expression, MergeAttributes( new RouteValueDictionary { { "type", "password" } }, htmlAttributes)); } - public static HtmlString ngTextBoxFor(this IHtmlHelper html, Expression> expression) + public static IHtmlContent ngTextBoxFor(this IHtmlHelper html, Expression> expression) { return html.ngTextBoxFor(expression, new RouteValueDictionary()); } - public static HtmlString ngTextBoxFor(this IHtmlHelper html, Expression> expression, object htmlAttributes) + public static IHtmlContent ngTextBoxFor(this IHtmlHelper html, Expression> expression, object htmlAttributes) { return html.ngTextBoxFor(expression, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } - public static HtmlString ngTextBoxFor(this IHtmlHelper html, Expression> expression, IDictionary htmlAttributes) + public static IHtmlContent ngTextBoxFor(this IHtmlHelper html, Expression> expression, IDictionary htmlAttributes) { var expressionText = ExpressionHelper.GetExpressionText(expression); var modelExplorer = ExpressionMetadataProvider.FromLambdaExpression(expression, html.ViewData, html.MetadataProvider); @@ -140,27 +141,9 @@ namespace Microsoft.AspNet.Mvc.Rendering var tag = new TagBuilder("input"); tag.MergeAttributes(MergeAttributes(ngAttributes, htmlAttributes)); - return tag.ToHtmlString(TagRenderMode.SelfClosing); + return tag.ToHtmlContent(TagRenderMode.SelfClosing); } - //private static bool IsNumberType(Type type) - //{ - // switch (Type.GetTypeCode(type)) - // { - // case TypeCode.Int16: - // case TypeCode.Int32: - // case TypeCode.Int64: - // case TypeCode.UInt16: - // case TypeCode.UInt32: - // case TypeCode.UInt64: - // case TypeCode.Decimal: - // case TypeCode.Double: - // case TypeCode.Single: - // return true; - // } - // return false; - //} - private static bool IsNumberType(Type type) { if (type == typeof(Int16) || @@ -207,12 +190,12 @@ namespace Microsoft.AspNet.Mvc.Rendering return false; } - public static HtmlString ngDropDownListFor(this IHtmlHelper html, Expression> propertyExpression, Expression> displayExpression, string source, string nullOption, object htmlAttributes) + public static IHtmlContent ngDropDownListFor(this IHtmlHelper html, Expression> propertyExpression, Expression> displayExpression, string source, string nullOption, object htmlAttributes) { return ngDropDownListFor(html, propertyExpression, displayExpression, source, nullOption, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } - public static HtmlString ngDropDownListFor(this IHtmlHelper html, Expression> propertyExpression, Expression> displayExpression, string source, string nullOption, IDictionary htmlAttributes) + public static IHtmlContent ngDropDownListFor(this IHtmlHelper html, Expression> propertyExpression, Expression> displayExpression, string source, string nullOption, IDictionary htmlAttributes) { var propertyExpressionText = ExpressionHelper.GetExpressionText(propertyExpression); var displayExpressionText = ExpressionHelper.GetExpressionText(displayExpression); @@ -238,7 +221,7 @@ namespace Microsoft.AspNet.Mvc.Rendering var nullOptionTag = new TagBuilder("option"); nullOptionTag.Attributes["value"] = string.Empty; nullOptionTag.SetInnerText(nullOption); - tag.InnerHtml = nullOptionTag.ToString(); + tag.InnerHtml = nullOptionTag.ToHtmlContent(TagRenderMode.Normal); } var clientValidators = html.GetClientValidationRules(metadata, null); @@ -250,20 +233,20 @@ namespace Microsoft.AspNet.Mvc.Rendering tag.MergeAttributes(htmlAttributes, replaceExisting: true); - return tag.ToHtmlString(TagRenderMode.Normal); + return tag.ToHtmlContent(TagRenderMode.Normal); } - public static HtmlString ngValidationMessageFor(this IHtmlHelper htmlHelper, Expression> expression, string formName) + public static IHtmlContent ngValidationMessageFor(this IHtmlHelper htmlHelper, Expression> expression, string formName) { return ngValidationMessageFor(htmlHelper, expression, formName, ((IDictionary)new RouteValueDictionary())); } - public static HtmlString ngValidationMessageFor(this IHtmlHelper htmlHelper, Expression> expression, string formName, object htmlAttributes) + public static IHtmlContent ngValidationMessageFor(this IHtmlHelper htmlHelper, Expression> expression, string formName, object htmlAttributes) { return ngValidationMessageFor(htmlHelper, expression, formName, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } - public static HtmlString ngValidationMessageFor(this IHtmlHelper html, Expression> expression, string formName, IDictionary htmlAttributes) + public static IHtmlContent ngValidationMessageFor(this IHtmlHelper html, Expression> expression, string formName, IDictionary htmlAttributes) { var expressionText = ExpressionHelper.GetExpressionText(expression); var metadata = ExpressionMetadataProvider.FromLambdaExpression(expression, html.ViewData, html.MetadataProvider); @@ -309,7 +292,7 @@ namespace Microsoft.AspNet.Mvc.Rendering tags.Add(tag); } - return html.Raw(String.Concat(tags.Select(t => t.ToString()))); + return new HtmlString(String.Concat(tags.Select(t => t.ToString()))); } public static string ngValidationClassFor(this IHtmlHelper html, Expression> expression, string formName, string className) diff --git a/src/MusicStore.Spa/Helpers/GeneralExtensions.cs b/src/MusicStore.Spa/Helpers/GeneralExtensions.cs deleted file mode 100644 index 76ee8c0605..0000000000 --- a/src/MusicStore.Spa/Helpers/GeneralExtensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Microsoft.AspNet.Mvc.Rendering -{ - public static class GeneralExtensions - { - public static HtmlString Tag(this IHtmlHelper htmlHelper, TagBuilder tagBuilder) - { - return htmlHelper.Raw(tagBuilder.ToString()); - } - } -} \ No newline at end of file diff --git a/src/MusicStore.Spa/Helpers/JsonExtensions.cs b/src/MusicStore.Spa/Helpers/JsonExtensions.cs index f1a36a6ac4..ee2c9c34a9 100644 --- a/src/MusicStore.Spa/Helpers/JsonExtensions.cs +++ b/src/MusicStore.Spa/Helpers/JsonExtensions.cs @@ -1,37 +1,36 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.AspNet.Routing; using Newtonsoft.Json; +using Microsoft.AspNet.Html.Abstractions; namespace Microsoft.AspNet.Mvc.Rendering { public static class JsonExtensions { - public static HtmlString Json(this IHtmlHelper helper, TData data) + public static IHtmlContent Json(this IHtmlHelper helper, TData data) { return Json(helper, data, new RouteValueDictionary()); } - public static HtmlString Json(this IHtmlHelper helper, TData data, object htmlAttributes) + public static IHtmlContent Json(this IHtmlHelper helper, TData data, object htmlAttributes) { return Json(helper, data, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); } - public static HtmlString Json(this IHtmlHelper helper, TData data, IDictionary htmlAttributes) + public static IHtmlContent Json(this IHtmlHelper helper, TData data, IDictionary htmlAttributes) { var builder = new TagBuilder("script"); builder.Attributes["type"] = "application/json"; builder.MergeAttributes(htmlAttributes); - builder.InnerHtml = - (data is JsonString - ? data.ToString() - : JsonConvert.SerializeObject(data)) - .Replace("<", "\u003C").Replace(">", "\u003E"); - return helper.Tag(builder); + var innerContent = data is JsonString ? data.ToString() : JsonConvert.SerializeObject(data); + innerContent.Replace("<", "\u003C").Replace(">", "\u003E"); + builder.InnerHtml = new HtmlString(innerContent); + + return builder.ToHtmlContent(TagRenderMode.Normal); } - public static HtmlString InlineData(this IHtmlHelper helper, string actionName, string controllerName) + public static IHtmlContent InlineData(this IHtmlHelper helper, string actionName, string controllerName) { //var result = helper.Action(actionName, controllerName); //var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);