ResultFilter attribute added to sample
This commit is contained in:
parent
772f833dc9
commit
a55a71a4f8
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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": ""
|
||||
|
|
|
|||
Loading…
Reference in New Issue