MVC1002: Route attribute cannot be applied to page handler methods
Value | |
---|---|
Rule ID | MVC1002 |
Fix is breaking or non-breaking | Non-breaking |
Cause
An attribute implementing IRouteTemplateProvider was applied to a Razor Page handler method.
Rule description
Razor Page handler methods are selected after routing is completed, and consequently cannot contribute a route. Applying a route attribute such as HttpGet
or HttpPost
to a Razor Page handler is not supported.
public class IndexModel : PageModel
{
[HttpGet("/my-url")]
public IActionResult OnGet() => Page();
}
How to fix violations
Remove the route attribute from the handler. 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.
Cộng tác với chúng tôi trên GitHub
Bạn có thể tìm thấy nguồn cho nội dung này trên GitHub, nơi bạn cũng có thể tạo và xem lại các vấn đề và yêu cầu kéo. Để biết thêm thông tin, hãy xem hướng dẫn dành cho người đóng góp của chúng tôi.
ASP.NET Core