ResultFilter attribute added to sample

This commit is contained in:
Yishai Galatzer 2014-03-05 21:08:23 -08:00
parent 772f833dc9
commit a55a71a4f8
3 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,27 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using MvcSample.Models;
namespace MvcSample.Filters
{
public class InspectResultPageAttribute : ActionResultFilterAttribute
{
public async override Task Invoke(ActionResultFilterContext context, Func<Task> next)
{
ViewResult viewResult = context.Result as ViewResult;
if (viewResult != null)
{
User user = viewResult.ViewData.Model as User;
if (user != null)
{
user.Name += "**" + user.Name + "**";
}
}
await next();
}
}
}

View File

@ -17,6 +17,7 @@ namespace MvcSample
// TODO: Add a real filter here
[ServiceFilter(typeof(PassThroughAttribute))]
[AgeEnhancer]
[InspectResultPage]
public IActionResult Index(int age)
{
_user.Age = age;

View File

@ -5,6 +5,7 @@
"Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*",
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*",
"Microsoft.AspNet.Routing" : "0.1-alpha-*",
"Microsoft.AspNet.Mvc.ModelBinding" : "",
"Microsoft.AspNet.Mvc.Core" : "",
"Microsoft.AspNet.Mvc" : "",
"Microsoft.AspNet.Mvc.Razor": ""