Support specifying paths starting with ~/ for layout and partial views
Fixes #821
This commit is contained in:
parent
4baa2910b7
commit
ba6813a418
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Mvc.Core;
|
|
||||||
using Microsoft.Framework.DependencyInjection;
|
using Microsoft.Framework.DependencyInjection;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor
|
namespace Microsoft.AspNet.Mvc.Razor
|
||||||
|
|
@ -32,6 +31,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IRazorPage CreateInstance([NotNull] string relativePath, bool enableInstrumentation)
|
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);
|
var fileInfo = _fileInfoCache.GetFileInfo(relativePath);
|
||||||
|
|
||||||
if (fileInfo != null)
|
if (fileInfo != null)
|
||||||
|
|
|
||||||
|
|
@ -69,11 +69,14 @@ ViewWithNestedLayout-Content
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RazorView_ExecutesPartialPagesWithCorrectContext()
|
public async Task RazorView_ExecutesPartialPagesWithCorrectContext()
|
||||||
{
|
{
|
||||||
var expected =
|
var expected = string.Join(Environment.NewLine,
|
||||||
@"<partial>98052
|
"<partial>98052",
|
||||||
|
"",
|
||||||
</partial>
|
"</partial>",
|
||||||
test-value";
|
"<partial2>98052",
|
||||||
|
"",
|
||||||
|
"</partial2>",
|
||||||
|
"test-value");
|
||||||
var server = TestServer.Create(_provider, _app);
|
var server = TestServer.Create(_provider, _app);
|
||||||
var client = server.CreateClient();
|
var client = server.CreateClient();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
@{
|
@{
|
||||||
Layout = "/Views/Shared/_Layout.cshtml";
|
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||||
}
|
}
|
||||||
ViewWithFullPath-content
|
ViewWithFullPath-content
|
||||||
|
|
@ -2,4 +2,6 @@
|
||||||
@model Person
|
@model Person
|
||||||
<partial>@await Html.PartialAsync("_Partial", Model.Address)
|
<partial>@await Html.PartialAsync("_Partial", Model.Address)
|
||||||
</partial>
|
</partial>
|
||||||
|
<partial2>@await Html.PartialAsync("~/Views/Shared/_Partial.cshtml", Model.Address)
|
||||||
|
</partial2>
|
||||||
@ViewBag.TestKey
|
@ViewBag.TestKey
|
||||||
Loading…
Reference in New Issue