MVC1001: Filters cannot be applied to page handler methods
Value | |
---|---|
Rule ID | MVC1001 |
Fix is breaking or non-breaking | Non-breaking |
Cause
An attribute implementing IFilterMetadata was applied to a Razor Page handler method.
Rule description
Razor Page handler methods are selected after MVC filter execution has started, and consequently cannot contribute filters to execute. Applying a filter to a Razor Page handler is unsupported and always incorrect.
public class IndexModel : PageModel
{
[MyFilter]
public IActionResult OnGet() => Page();
}
How to fix violations
Remove the filter from the handler and apply it to the page model. If a filter has to be applied to a specific handler, consider using multiple Razor Pages.
[MyFilter]
public class IndexModel : PageModel
{
public IActionResult OnGet() => Page();
}
When to suppress warnings
Don't suppress warnings from this rule.
ASP.NET Core
Σχόλια
https://aka.ms/ContentUserFeedback.
Σύντομα διαθέσιμα: Καθ' όλη τη διάρκεια του 2024 θα καταργήσουμε σταδιακά τα ζητήματα GitHub ως μηχανισμό ανάδρασης για το περιεχόμενο και θα το αντικαταστήσουμε με ένα νέο σύστημα ανάδρασης. Για περισσότερες πληροφορίες, ανατρέξτε στο θέμα:Υποβολή και προβολή σχολίων για