MVC1003: Route attributes cannot be applied to page models
Value | |
---|---|
Rule ID | MVC1003 |
Fix is breaking or non-breaking | Non-breaking |
Cause
An attribute implementing IRouteTemplateProvider was applied to a Razor Page model.
Rule description
Razor Page models are identified after routing is completed, and consequently cannot contribute a route. Applying a route attribute such as Route
to a Razor Page model is not supported.
[Route("/my-page-route")]
public class IndexModel : PageModel
{
public IActionResult OnGet() => Page();
}
How to fix violations
Remove the route attribute from the page model. Routes can be specified for a Razor Page using an @page
directive or by using conventions. For more information, see custom routes in Razor Pages.
When to suppress warnings
Don't suppress warnings from this rule.
Colaborați cu noi pe GitHub
Sursa pentru acest conținut poate fi găsită pe GitHub, unde puteți, de asemenea, să creați și să consultați probleme și solicitări de tragere. Pentru mai multe informații, consultați ghidul nostru pentru colaboratori.
Feedback
https://aka.ms/ContentUserFeedback.
În curând: Pe parcursul anului 2024, vom elimina treptat Probleme legate de GitHub ca mecanism de feedback pentru conținut și îl vom înlocui cu un nou sistem de feedback. Pentru mai multe informații, consultați:Trimiteți și vizualizați feedback pentru