Skip to content

Instantly share code, notes, and snippets.

@scottaddie
Last active January 30, 2017 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottaddie/4b3b1d38533aa4454c65d388d3475cb3 to your computer and use it in GitHub Desktop.
Save scottaddie/4b3b1d38533aa4454c65d388d3475cb3 to your computer and use it in GitHub Desktop.
Custom context class for communicating from parent to child tag helper
public class HandContext
{
public string Player { get; set; }
}
[HtmlTargetElement(Constants.HAND_TAG_HELPER_ELEMENT_NAME, Attributes = nameof(Player), TagStructure = TagStructure.NormalOrSelfClosing)]
[RestrictChildren(Constants.CARD_TAG_HELPER_ELEMENT_NAME)]
public class HandTagHelper : TagHelper
{
public string Player { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
// Assign the lowercase version of the player's name to the appropriate context property
var handContext = new HandContext
{
Player = Player?.Trim().ToLower()
};
context.Items.Add(typeof(HandTagHelper), handContext);
output.TagName = "div";
output.Attributes.SetAttribute("class", "row");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment