Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit ba6813a

Browse files
committed
Support specifying paths starting with ~/ for layout and partial views
Fixes #821
1 parent 4baa291 commit ba6813a

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/Microsoft.AspNet.Mvc.Razor/VirtualPathRazorPageFactory.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using Microsoft.AspNet.Mvc.Core;
65
using Microsoft.Framework.DependencyInjection;
76

87
namespace Microsoft.AspNet.Mvc.Razor
@@ -32,6 +31,12 @@ public VirtualPathRazorPageFactory(IRazorCompilationService compilationService,
3231
/// <inheritdoc />
3332
public IRazorPage CreateInstance([NotNull] string relativePath, bool enableInstrumentation)
3433
{
34+
if (relativePath.StartsWith("~/", StringComparison.Ordinal))
35+
{
36+
// For tilde slash paths, drop the leading ~ to make it work with the underlying IFileSystem.
37+
relativePath = relativePath.Substring(1);
38+
}
39+
3540
var fileInfo = _fileInfoCache.GetFileInfo(relativePath);
3641

3742
if (fileInfo != null)

test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ public async Task RazorView_ExecutesPageAndLayout(string actionName, string expe
6969
[Fact]
7070
public async Task RazorView_ExecutesPartialPagesWithCorrectContext()
7171
{
72-
var expected =
73-
@"<partial>98052
74-
75-
</partial>
76-
test-value";
72+
var expected = string.Join(Environment.NewLine,
73+
"<partial>98052",
74+
"",
75+
"</partial>",
76+
"<partial2>98052",
77+
"",
78+
"</partial2>",
79+
"test-value");
7780
var server = TestServer.Create(_provider, _app);
7881
var client = server.CreateClient();
7982

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@{
2-
Layout = "/Views/Shared/_Layout.cshtml";
2+
Layout = "~/Views/Shared/_Layout.cshtml";
33
}
44
ViewWithFullPath-content

test/WebSites/RazorWebSite/Views/ViewEngine/ViewWithPartial.cshtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
@model Person
33
<partial>@await Html.PartialAsync("_Partial", Model.Address)
44
</partial>
5+
<partial2>@await Html.PartialAsync("~/Views/Shared/_Partial.cshtml", Model.Address)
6+
</partial2>
57
@ViewBag.TestKey

0 commit comments

Comments
 (0)