MVC1006: Methods containing TagHelpers must be async and return Task
Value | |
---|---|
Rule ID | MVC1006 |
Fix is breaking or non-breaking | Breaking |
Cause
A tag helper was defined inside a Razor function that executes synchronously
Rule description
Tag Helper execution is asynchronous. When used inside a method or a lambda within a Razor Page, the containing function must also be declared to be async.
Consider the following cshtml file:
void Helper(string controller)
{
<a asp-controller="@controller">Home</a>
}
asp-controller
is a tag helper and will trigger this rule.
How to fix violations
Declare the function to be async and Task returning:
async Task Helper(string controller)
{
<a asp-controller="@controller">Home</a>
}
When to suppress warnings
Do not suppress a warning 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
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho