diff --git a/src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs b/src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs index 2930669267..ee28806b5d 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNet.Mvc.Core; using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.Mvc.Razor @@ -32,6 +31,12 @@ namespace Microsoft.AspNet.Mvc.Razor /// public IRazorPage CreateInstance([NotNull] string relativePath, bool enableInstrumentation) { + if (relativePath.StartsWith("~/", StringComparison.Ordinal)) + { + // For tilde slash paths, drop the leading ~ to make it work with the underlying IFileSystem. + relativePath = relativePath.Substring(1); + } + var fileInfo = _fileInfoCache.GetFileInfo(relativePath); if (fileInfo != null) diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs index b1839be16a..af0d9623f4 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs @@ -69,11 +69,14 @@ ViewWithNestedLayout-Content [Fact] public async Task RazorView_ExecutesPartialPagesWithCorrectContext() { - var expected = -@"98052 - - -test-value"; + var expected = string.Join(Environment.NewLine, + "98052", + "", + "", + "98052", + "", + "", + "test-value"); var server = TestServer.Create(_provider, _app); var client = server.CreateClient(); diff --git a/test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithFullPath.cshtml b/test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithFullPath.cshtml index 00b84b6ee8..0c334f0585 100644 --- a/test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithFullPath.cshtml +++ b/test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithFullPath.cshtml @@ -1,4 +1,4 @@ @{ - Layout = "/Views/Shared/_Layout.cshtml"; + Layout = "~/Views/Shared/_Layout.cshtml"; } ViewWithFullPath-content \ No newline at end of file diff --git a/test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithPartial.cshtml b/test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithPartial.cshtml index c696e6cb3a..e861b5f74d 100644 --- a/test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithPartial.cshtml +++ b/test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithPartial.cshtml @@ -2,4 +2,6 @@ @model Person @await Html.PartialAsync("_Partial", Model.Address) +@await Html.PartialAsync("~/Views/Shared/_Partial.cshtml", Model.Address) + @ViewBag.TestKey \ No newline at end of file