diff --git a/WebFx.sln b/WebFx.sln index b099129a1a..bc4c442b21 100644 --- a/WebFx.sln +++ b/WebFx.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30110.0 +VisualStudioVersion = 12.0.21005.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DAAE4C74-D06F-4874-A166-33305D2643CE}" EndProject @@ -59,6 +59,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Mvc.Razor. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestCommon.net45", "test\TestCommon\TestCommon.net45.csproj", "{75A07B53-C5EE-4995-A55B-27562C23BCCD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Mvc.Rendering.Test.net45", "test\Microsoft.AspNet.Mvc.Rendering.Test\Microsoft.AspNet.Mvc.Rendering.Test.net45.csproj", "{68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -149,6 +151,10 @@ Global {75A07B53-C5EE-4995-A55B-27562C23BCCD}.Debug|Any CPU.Build.0 = Debug|Any CPU {75A07B53-C5EE-4995-A55B-27562C23BCCD}.Release|Any CPU.ActiveCfg = Release|Any CPU {75A07B53-C5EE-4995-A55B-27562C23BCCD}.Release|Any CPU.Build.0 = Release|Any CPU + {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -179,5 +185,6 @@ Global {537CC0EE-4B62-4789-9AE9-94BE28E0D25A} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {3EB2CFF9-6E67-4C03-9AC4-2DD169024938} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {75A07B53-C5EE-4995-A55B-27562C23BCCD} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} + {68FC3791-A9E4-4EDE-93A5-C7AC7DC0ED6E} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} EndGlobalSection EndGlobal diff --git a/samples/MvcSample/project.json b/samples/MvcSample/project.json index 45c87bf5b9..c4ef088f35 100644 --- a/samples/MvcSample/project.json +++ b/samples/MvcSample/project.json @@ -8,7 +8,8 @@ "Microsoft.AspNet.Mvc.ModelBinding" : "", "Microsoft.AspNet.Mvc.Core" : "", "Microsoft.AspNet.Mvc" : "", - "Microsoft.AspNet.Mvc.Razor": "" + "Microsoft.AspNet.Mvc.Razor": "", + "Microsoft.AspNet.Mvc.Rendering" : "" }, "configurations": { "net45": { diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs index c454eec5c7..6a20f28b49 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs @@ -35,10 +35,7 @@ namespace Microsoft.AspNet.Mvc context.HttpContext.Response.ContentType = "text/html"; using (var writer = new StreamWriter(context.HttpContext.Response.Body, Encoding.UTF8, 1024, leaveOpen: true)) { - var viewContext = new ViewContext(context.HttpContext, context.RouteValues, ViewData) - { - ServiceProvider = _serviceProvider - }; + var viewContext = new ViewContext(context.HttpContext, ViewData, _serviceProvider); await view.RenderAsync(viewContext, writer); } } diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/Resources.resx b/src/Microsoft.AspNet.Mvc.ModelBinding/Resources.resx index 3b8cbc9202..235940cfbf 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/Resources.resx +++ b/src/Microsoft.AspNet.Mvc.ModelBinding/Resources.resx @@ -153,10 +153,4 @@ The parameter conversion from type '{0}' to type '{1}' failed because no type converter can convert between these types. - - The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'. - - - The model item passed into the ViewData is of type '{0}', but this ViewData instance requires a model item of type '{1}'. - \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/ViewContext.cs b/src/Microsoft.AspNet.Mvc.ModelBinding/ViewContext.cs deleted file mode 100644 index 1bc8ba2f9f..0000000000 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/ViewContext.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.AspNet.Abstractions; - -namespace Microsoft.AspNet.Mvc.ModelBinding -{ - public class ViewContext : RequestContext - { - public ViewContext(HttpContext context, IDictionary routeValues, ViewData viewData) : - base(context, routeValues) - { - ViewData = viewData; - } - - public IServiceProvider ServiceProvider { get; set; } - - public ViewData ViewData { get; private set; } - } -} diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorViewOfT.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorViewOfT.cs index b979834035..767f1bf412 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorViewOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorViewOfT.cs @@ -27,9 +27,9 @@ namespace Microsoft.AspNet.Mvc.Razor return base.RenderAsync(context, writer); } - private void InitHelpers(RequestContext context) + private void InitHelpers(ViewContext context) { - Html = new HtmlHelper(context, ViewData); + Html = new HtmlHelper(context.HttpContext, ViewData); } } } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs index 2c9fee03a9..9dd521e838 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs @@ -1,14 +1,13 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System; -using System.Reflection; using System.Collections.Generic; -using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net; +using System.Reflection; using System.Text; -using Microsoft.AspNet.Mvc.ModelBinding; +using Microsoft.AspNet.Abstractions; namespace Microsoft.AspNet.Mvc { @@ -21,23 +20,16 @@ namespace Microsoft.AspNet.Mvc public static readonly string ValidationSummaryCssClassName = "validation-summary-errors"; public static readonly string ValidationSummaryValidCssClassName = "validation-summary-valid"; - private static readonly object _html5InputsModeKey = new object(); - - public HtmlHelper(RequestContext requestContext, ViewData viewData) + public HtmlHelper([NotNull] HttpContext httpContext, ViewData viewData) { - if (requestContext == null) - { - throw new ArgumentNullException("requestContext"); - } - - RequestContext = requestContext; + HttpContext = httpContext; ViewData = viewData; // ClientValidationRuleFactory = (name, metadata) => ModelValidatorProviders.Providers.GetValidators(metadata ?? ModelMetadata.FromStringExpression(name, ViewData), ViewContext).SelectMany(v => v.GetClientValidationRules()); } //internal Func> ClientValidationRuleFactory { get; set; } - public RequestContext RequestContext { get; private set; } + public HttpContext HttpContext { get; private set; } public ViewData ViewData { @@ -164,38 +156,6 @@ namespace Microsoft.AspNet.Mvc return TagBuilder.CreateSanitizedId(name); } - //public static string GenerateLink(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary htmlAttributes) - //{ - // return GenerateLink(requestContext, routeCollection, linkText, routeName, actionName, controllerName, null /* protocol */, null /* hostName */, null /* fragment */, routeValues, htmlAttributes); - //} - - //public static string GenerateLink(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary htmlAttributes) - //{ - // return GenerateLinkInternal(requestContext, routeCollection, linkText, routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, htmlAttributes, true /* includeImplicitMvcValues */); - //} - - //private static string GenerateLinkInternal(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary htmlAttributes, bool includeImplicitMvcValues) - //{ - // string url = UrlHelper.GenerateUrl(routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, routeCollection, requestContext, includeImplicitMvcValues); - // TagBuilder tagBuilder = new TagBuilder("a") - // { - // InnerHtml = (!String.IsNullOrEmpty(linkText)) ? HttpUtility.HtmlEncode(linkText) : String.Empty - // }; - // tagBuilder.MergeAttributes(htmlAttributes); - // tagBuilder.MergeAttribute("href", url); - // return tagBuilder.ToString(TagRenderMode.Normal); - //} - - //public static string GenerateRouteLink(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, RouteValueDictionary routeValues, IDictionary htmlAttributes) - //{ - // return GenerateRouteLink(requestContext, routeCollection, linkText, routeName, null /* protocol */, null /* hostName */, null /* fragment */, routeValues, htmlAttributes); - //} - - //public static string GenerateRouteLink(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary htmlAttributes) - //{ - // return GenerateLinkInternal(requestContext, routeCollection, linkText, routeName, null /* actionName */, null /* controllerName */, protocol, hostName, fragment, routeValues, htmlAttributes, false /* includeImplicitMvcValues */); - //} - public static string GetFormMethodString(FormMethod method) { switch (method) diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs index eb330ced60..41e9d7e581 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelperOfT.cs @@ -1,18 +1,12 @@ -using System; -using Microsoft.AspNet.Mvc.ModelBinding; +using Microsoft.AspNet.Abstractions; namespace Microsoft.AspNet.Mvc { public class HtmlHelper : HtmlHelper { - public HtmlHelper(RequestContext requestContext, ViewData viewData) - : base(requestContext, viewData) + public HtmlHelper([NotNull]HttpContext httpContext, ViewData viewData) + : base(httpContext, viewData) { - if (requestContext == null) - { - throw new ArgumentNullException("requestContext"); - } - ViewData = viewData; } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..15ace04265 --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.Designer.cs @@ -0,0 +1,62 @@ +// +namespace Microsoft.AspNet.Mvc.Rendering +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class Resources + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNet.Mvc.Rendering.Resources", typeof(Resources).GetTypeInfo().Assembly); + + /// + /// The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'. + /// + internal static string ViewData_ModelCannotBeNull + { + get { return GetString("ViewData_ModelCannotBeNull"); } + } + + /// + /// The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'. + /// + internal static string FormatViewData_ModelCannotBeNull(object p0) + { + return string.Format(CultureInfo.CurrentCulture, GetString("ViewData_ModelCannotBeNull"), p0); + } + + /// + /// The model item passed into the ViewData is of type '{0}', but this ViewData instance requires a model item of type '{1}'. + /// + internal static string ViewData_WrongTModelType + { + get { return GetString("ViewData_WrongTModelType"); } + } + + /// + /// The model item passed into the ViewData is of type '{0}', but this ViewData instance requires a model item of type '{1}'. + /// + internal static string FormatViewData_WrongTModelType(object p0, object p1) + { + return string.Format(CultureInfo.CurrentCulture, GetString("ViewData_WrongTModelType"), p0, p1); + } + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.resx b/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.resx new file mode 100644 index 0000000000..e8cf52bbb7 --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Rendering/Properties/Resources.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The model item passed is null, but this ViewData instance requires a non-null model item of type '{0}'. + + + The model item passed into the ViewData is of type '{0}', but this ViewData instance requires a model item of type '{1}'. + + \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs new file mode 100644 index 0000000000..370d42f1f9 --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewContext.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.AspNet.Abstractions; + +namespace Microsoft.AspNet.Mvc +{ + public class ViewContext + { + public ViewContext(HttpContext context, ViewData viewData, IServiceProvider serviceProvider) + { + HttpContext = context; + ViewData = viewData; + ServiceProvider = serviceProvider; + } + + public HttpContext HttpContext { get; private set; } + + public IServiceProvider ServiceProvider { get; private set; } + + public ViewData ViewData { get; private set; } + } +} diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/ViewData.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewData.cs similarity index 98% rename from src/Microsoft.AspNet.Mvc.ModelBinding/ViewData.cs rename to src/Microsoft.AspNet.Mvc.Rendering/View/ViewData.cs index 94b0aa91f0..b572c480d2 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/ViewData.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewData.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Dynamic; -namespace Microsoft.AspNet.Mvc.ModelBinding +namespace Microsoft.AspNet.Mvc { public class ViewData : DynamicObject { diff --git a/src/Microsoft.AspNet.Mvc.ModelBinding/ViewDataOfTModel.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewDataOfTModel.cs similarity index 90% rename from src/Microsoft.AspNet.Mvc.ModelBinding/ViewDataOfTModel.cs rename to src/Microsoft.AspNet.Mvc.Rendering/View/ViewDataOfTModel.cs index 108a2aaf5b..4a42e88e3a 100644 --- a/src/Microsoft.AspNet.Mvc.ModelBinding/ViewDataOfTModel.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/ViewDataOfTModel.cs @@ -1,8 +1,9 @@ using System; using System.Globalization; using Microsoft.AspNet.Mvc.ModelBinding.Internal; +using Microsoft.AspNet.Mvc.Rendering; -namespace Microsoft.AspNet.Mvc.ModelBinding +namespace Microsoft.AspNet.Mvc { public class ViewData : ViewData { @@ -36,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding string message; if (value == null) { - message = String.Format(CultureInfo.CurrentCulture, Resources.ViewDataDictionary_ModelCannotBeNull, typeof(TModel)); + message = String.Format(CultureInfo.CurrentCulture, Resources.ViewData_ModelCannotBeNull, typeof(TModel)); } else { diff --git a/src/Microsoft.AspNet.Mvc.Rendering/project.json b/src/Microsoft.AspNet.Mvc.Rendering/project.json index 8b5ca2cdca..72f77e6a21 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/project.json +++ b/src/Microsoft.AspNet.Mvc.Rendering/project.json @@ -18,6 +18,7 @@ "System.IO": "4.0.0.0", "System.Reflection": "4.0.10.0", "System.Reflection.Extensions": "4.0.0.0", + "System.Resources.ResourceManager": "4.0.0.0", "System.Runtime": "4.0.20.0", "System.Runtime.Extensions": "4.0.10.0", "System.Runtime.InteropServices": "4.0.10.0", diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/ViewDataOfTTest.cs b/test/Microsoft.AspNet.Mvc.Rendering.Test/ViewDataOfTTest.cs similarity index 90% rename from test/Microsoft.AspNet.Mvc.ModelBinding.Test/ViewDataOfTTest.cs rename to test/Microsoft.AspNet.Mvc.Rendering.Test/ViewDataOfTTest.cs index eabb75bd4b..a7c4221cbb 100644 --- a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/ViewDataOfTTest.cs +++ b/test/Microsoft.AspNet.Mvc.Rendering.Test/ViewDataOfTTest.cs @@ -1,11 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xunit; -namespace Microsoft.AspNet.Mvc.ModelBinding.Test +namespace Microsoft.AspNet.Mvc.Rendering.Test { public class ViewDataOfTTest { diff --git a/test/Microsoft.AspNet.Mvc.ModelBinding.Test/ViewDataTest.cs b/test/Microsoft.AspNet.Mvc.Rendering.Test/ViewDataTest.cs similarity index 100% rename from test/Microsoft.AspNet.Mvc.ModelBinding.Test/ViewDataTest.cs rename to test/Microsoft.AspNet.Mvc.Rendering.Test/ViewDataTest.cs diff --git a/test/Microsoft.AspNet.Mvc.Rendering.Test/project.json b/test/Microsoft.AspNet.Mvc.Rendering.Test/project.json new file mode 100644 index 0000000000..8f2c3f4780 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.Rendering.Test/project.json @@ -0,0 +1,15 @@ +{ + "version" : "0.1-alpha-*", + "dependencies": { + "Microsoft.AspNet.Abstractions": "0.1-alpha-*", + "Microsoft.AspNet.PipelineCore": "0.1-alpha-*", + "Microsoft.AspNet.Mvc.Rendering" : "", + "TestCommon" : "", + "Moq": "4.0.10827", + "Xunit": "1.9.1", + "Xunit.extensions": "1.9.1" + }, + "configurations": { + "net45": { } + } +} \ No newline at end of file