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.
|
||||
|
||||
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
|
|||
/// <inheritdoc />
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -69,11 +69,14 @@ ViewWithNestedLayout-Content
|
|||
[Fact]
|
||||
public async Task RazorView_ExecutesPartialPagesWithCorrectContext()
|
||||
{
|
||||
var expected =
|
||||
@"<partial>98052
|
||||
|
||||
</partial>
|
||||
test-value";
|
||||
var expected = string.Join(Environment.NewLine,
|
||||
"<partial>98052",
|
||||
"",
|
||||
"</partial>",
|
||||
"<partial2>98052",
|
||||
"",
|
||||
"</partial2>",
|
||||
"test-value");
|
||||
var server = TestServer.Create(_provider, _app);
|
||||
var client = server.CreateClient();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@{
|
||||
Layout = "/Views/Shared/_Layout.cshtml";
|
||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||
}
|
||||
ViewWithFullPath-content
|
||||
|
|
@ -2,4 +2,6 @@
|
|||
@model Person
|
||||
<partial>@await Html.PartialAsync("_Partial", Model.Address)
|
||||
</partial>
|
||||
<partial2>@await Html.PartialAsync("~/Views/Shared/_Partial.cshtml", Model.Address)
|
||||
</partial2>
|
||||
@ViewBag.TestKey
|
||||
Loading…
Reference in New Issue