The tag helper ‘input’ must not have C# in the element’s attribute declaration area

If you don’t need to use the TagHelper, you can use <!elementName> to disable it for a specific element:

<!textarea class="testClass" asp-for="testId" @readonlyAttribute>@Model.Id</!textarea>

See @glenn223’s answer for a more structural solution. I made an improved version of his solution, by adding support for anonymous objects:

using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace  {YourBaseNameSpace}.Helpers.TagHelpers
{
    [HtmlTargetElement(Attributes = "custom-attributes")]
    public class CustomAttributesTagHelper : TagHelper
    {
        public object CustomAttributes { get; set; }

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var customAttributesDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(CustomAttributes);
            foreach (var (key, value) in customAttributesDictionary)
            {
                output.Attributes.SetAttribute(key, value);
            }
        }
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)