Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom Tag Helper for rendering a LinkButton-like anchor in ASP.NET Core
[HtmlTargetElement("link-button")]
public class LinkButtonTagHelper : TagHelper
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
const string HIDDEN_FIELD_ID = "form_marker";
output.TagName = "a";
output.Attributes.SetAttribute("onclick",
$@"document.getElementById(""{HIDDEN_FIELD_ID}"").form.submit();");
output.PostElement.SetHtmlContent($@"<input type=""hidden"" id=""{HIDDEN_FIELD_ID}"" />");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.