Wie man das aktuelle Modell in den Aktionsfilter bringt
Ich habe einen generischen Aktionsfilter, und ich möchte das aktuelle Modell im @ erhalteOnActionExecuting
Methode. Meine aktuelle Implementierung ist wie folgt:
public class CommandFilter<T> : IActionFilter where T : class, new()
{
public void OnActionExecuting(ActionExecutingContext actionContext)
{
var model= (T)actionContext.ActionArguments["model"];
}
}
Es funktioniert gut, wenn alle Modellnamen gleich sind. Aber ich möchte verschiedene Modellnamen verwenden.
Wie kann man dieses Problem lösen?
Bearbeite
public class HomeController : Controller
{
[ServiceFilter(typeof(CommandActionFilter<CreateInput>))]
public IActionResult Create([FromBody]CreateInput model)
{
return new OkResult();
}
}