public override Task ExecuteAsync(ActionContext context, ObjectResult objectResult) { var ctx = new ObjectResultContext { Request = context.HttpContext.Request, Response = context.HttpContext.Response, Model = objectResult.Value, ObjectResult = objectResult, ActionContext = context }; var config = ctx.GetService <ObjectResultConfiguration>(); var rules = config.Rules; Task task = null; foreach (var rule in rules) { if (rule.When(ctx)) { task = rule.RespondWith(ctx); break; } } if (task != null) { return(task); } return(base.ExecuteAsync(context, objectResult)); }
public static ViewDataDictionary GetViewData(this ObjectResultContext ctx) { var metalDataProvider = ctx.GetService <IModelMetadataProvider>(); var viewData = new ViewDataDictionary(metalDataProvider, ctx.ActionContext.ModelState) { Model = ctx.Model }; return(viewData); }
public static ViewDataDictionary GetViewData(this ObjectResultContext ctx) { var viewData = (ViewDataDictionary)ctx.ActionContext.HttpContext.Items["Miru_ViewData"]; if (viewData == null) { var metalDataProvider = ctx.GetService <IModelMetadataProvider>(); viewData = new ViewDataDictionary(metalDataProvider, ctx.ActionContext.ModelState); } viewData.Model = ctx.Model; return(viewData); }