We are experiencing the following error when build ASP.NET Core MVC application which is recently migrated from .NET Core 2.2 to 3.0:
The tag helper 'input' (or 'textarea' or any other) must not have C# in the element's attribute declaration area.
We used Razor @functions
to return HTML attribute content in order to overcome that issue but it looks ugly when you use variable for returning it from function without any extra logic (function dummy(htmlAttributeContent)
return htmlAttributeContent
)
@{
var roAttrHTML = "";
if (!user.GotAccessToken("someToken")) {
roAttrHTML = " readonly=\"readonly\" ";
}
}
<textarea class="testClass" asp-for="testId" @readonlyAttribute>@Model.Id</textarea>
Actually we got error
The tag helper 'textarea' must not have C# in the element's attribute declaration area.
when compile our ASP.NET Core MVC application whereas we need to get approach (better without @functions
usage) which will provide us a way to overcome that issue (as we have plenty of pages with similar logic which we need to touch once and avoid any possible problems with presumable new changes in support of attributes in the future .NET Core versions)
@readonlyAttribute
?I could also get the same error in asp.net core 2.2.Why not tryreadonly=@readonlyAttribute
? – Grandmotherlyreadonly
attribute, once it's there, the field is readonly – Collaboration