diff --git a/samples/MvcSample.Web/Views/Home/FlushPoint.cshtml b/samples/MvcSample.Web/Views/Home/FlushPoint.cshtml
index 4e95f0aabf..a2f5dd1de1 100644
--- a/samples/MvcSample.Web/Views/Home/FlushPoint.cshtml
+++ b/samples/MvcSample.Web/Views/Home/FlushPoint.cshtml
@@ -45,8 +45,8 @@
Marketing: Marketing@example.com
+@await FlushAsync()
@{
- await FlushAsync();
await Task.Delay(TimeSpan.FromSeconds(1));
}
diff --git a/samples/MvcSample.Web/Views/Shared/_FlushPointLayout.cshtml b/samples/MvcSample.Web/Views/Shared/_FlushPointLayout.cshtml
index 36b59fd1bd..c62898b48e 100644
--- a/samples/MvcSample.Web/Views/Shared/_FlushPointLayout.cshtml
+++ b/samples/MvcSample.Web/Views/Shared/_FlushPointLayout.cshtml
@@ -24,7 +24,7 @@
- @{ await FlushAsync(); }
+ @await FlushAsync()
@RenderBody()
@RenderSection("content")
diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs
index 765006c249..2e63d1b060 100644
--- a/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs
+++ b/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs
@@ -544,8 +544,11 @@ namespace Microsoft.AspNet.Mvc.Razor
/// Invokes on writing out any buffered
/// content to the .
///
- /// A that represents the asynchronous flush operation.
- public Task FlushAsync()
+ /// A that represents the asynchronous flush operation and on
+ /// completion returns a .
+ /// The value returned is a token value that allows FlushAsync to succeed. However the
+ /// value does not represent the rendered content.
+ public async Task FlushAsync()
{
// If there are active writing scopes then we should throw. Cannot flush content that has the potential to
// change.
@@ -562,7 +565,8 @@ namespace Microsoft.AspNet.Mvc.Razor
throw new InvalidOperationException(message);
}
- return Output.FlushAsync();
+ await Output.FlushAsync();
+ return HtmlString.Empty;
}
///
diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
index 4ef8994fef..48c77e8125 100644
--- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs
@@ -98,10 +98,10 @@ namespace Microsoft.AspNet.Mvc.Razor
{
// Arrange
var viewContext = CreateViewContext();
- var page = CreatePage(v =>
+ var page = CreatePage(async v =>
{
v.StartWritingScope();
- v.FlushAsync();
+ await v.FlushAsync();
});
// Act
@@ -527,6 +527,25 @@ namespace Microsoft.AspNet.Mvc.Razor
await Assert.DoesNotThrowAsync(() => renderAsyncDelegate(TextWriter.Null));
}
+ [Fact]
+ public async Task FlushAsync_ReturnsEmptyHtmlString()
+ {
+ // Arrange
+ HtmlString actual = null;
+ var writer = new Mock();
+ var context = CreateViewContext(writer.Object);
+ var page = CreatePage(async p =>
+ {
+ actual = await p.FlushAsync();
+ }, context);
+
+ // Act
+ await page.ExecuteAsync();
+
+ // Assert
+ Assert.Same(HtmlString.Empty, actual);
+ }
+
[Fact]
public async Task WriteAttribute_CallsBeginAndEndContext_OnPageExecutionListenerContext()
{
diff --git a/test/WebSites/RazorWebSite/Views/FlushPoint/PageWithoutLayout.cshtml b/test/WebSites/RazorWebSite/Views/FlushPoint/PageWithoutLayout.cshtml
index 9c702434da..b25b173026 100644
--- a/test/WebSites/RazorWebSite/Views/FlushPoint/PageWithoutLayout.cshtml
+++ b/test/WebSites/RazorWebSite/Views/FlushPoint/PageWithoutLayout.cshtml
@@ -1,12 +1,12 @@
@inject WaitService WaitService
Initial content
+@await FlushAsync()
@{
- await FlushAsync();
WaitService.WaitForClient();
}
Secondary content
+@await FlushAsync()
@{
- await FlushAsync();
WaitService.WaitForClient();
}
Final content
diff --git a/test/WebSites/RazorWebSite/Views/Shared/_LayoutWithFlush.cshtml b/test/WebSites/RazorWebSite/Views/Shared/_LayoutWithFlush.cshtml
index c3be440959..ca791c8768 100644
--- a/test/WebSites/RazorWebSite/Views/Shared/_LayoutWithFlush.cshtml
+++ b/test/WebSites/RazorWebSite/Views/Shared/_LayoutWithFlush.cshtml
@@ -1,7 +1,7 @@
@inject WaitService WaitService
@ViewBag.Title
+@await FlushAsync()
@{
- await FlushAsync();
WaitService.WaitForClient();
}
@RenderBody()
diff --git a/test/WebSites/RazorWebSite/Views/Shared/_LayoutWithPartialAndFlush.cshtml b/test/WebSites/RazorWebSite/Views/Shared/_LayoutWithPartialAndFlush.cshtml
index 1c6110e38d..5f4e3bc31a 100644
--- a/test/WebSites/RazorWebSite/Views/Shared/_LayoutWithPartialAndFlush.cshtml
+++ b/test/WebSites/RazorWebSite/Views/Shared/_LayoutWithPartialAndFlush.cshtml
@@ -1,8 +1,8 @@
@inject WaitService WaitService
@ViewBag.Title
@RenderBody()
+@await FlushAsync()
@{
- await FlushAsync();
WaitService.WaitForClient();
}
@await Html.PartialAsync("_PartialThatSetsTitle")