Trigger view rendering asynchronously.

This is as simple as modifying the base class to return task and await the ExecuteAsync method.  Also added a piece to the sample project to verify functionality.
This commit is contained in:
N. Taylor Mullen 2014-03-13 16:51:51 -07:00
parent 0247c3a393
commit f8179f03e4
3 changed files with 12 additions and 4 deletions

View File

@ -6,6 +6,13 @@
string nullValue = null; string nullValue = null;
} }
@functions {
public async Task<string> AsyncValueRetrieval()
{
return "Hello World";
}
}
<div class="jumbotron"> <div class="jumbotron">
<h1>ASP.NET</h1> <h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p> <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
@ -13,7 +20,8 @@
</div> </div>
<div class="row"> <div class="row">
<h3 title="@Model.Name" class="@nullValue">Hello @Model.Name! Happy @Model.Age birthday.</h3> <h3 title="@Model.Name" class="@nullValue">Hello @Model.Name! Happy @Model.Age birthday.</h3>
<h3>This value was retrieved asynchronously: @(await AsyncValueRetrieval())</h3>
<div class="col-md-4"> <div class="col-md-4">
<h2>Getting started</h2> <h2>Getting started</h2>
<p> <p>

View File

@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Razor
_baseType = baseType; _baseType = baseType;
DefaultBaseClass = baseType + "<dynamic>"; DefaultBaseClass = baseType + "<dynamic>";
GeneratedClassContext = new GeneratedClassContext( GeneratedClassContext = new GeneratedClassContext(
executeMethodName: "Execute", executeMethodName: "ExecuteAsync",
writeMethodName: "Write", writeMethodName: "Write",
writeLiteralMethodName: "WriteLiteral", writeLiteralMethodName: "WriteLiteral",
writeToMethodName: "WriteTo", writeToMethodName: "WriteTo",

View File

@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Razor
using (var bodyWriter = new StringWriter(contentBuilder)) using (var bodyWriter = new StringWriter(contentBuilder))
{ {
Output = bodyWriter; Output = bodyWriter;
Execute(); await ExecuteAsync();
} }
var bodyContent = contentBuilder.ToString(); var bodyContent = contentBuilder.ToString();
@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Mvc.Razor
await layoutView.RenderAsync(context, writer); await layoutView.RenderAsync(context, writer);
} }
public abstract void Execute(); public abstract Task ExecuteAsync();
public virtual void Write(object value) public virtual void Write(object value)
{ {