Chapter 15 Slides
Chapter 15 Slides
How to work
with tag helpers,
partial views,
and view components
Knowledge
2. Distinguish between tag helper attributes and elements.
3. Explain how to register tag helpers.
4. Explain how to create custom tag helpers for standard and non-
standard HTML elements.
5. Describe the use of the HtmlTarget attribute to control the scope of
a tag helper.
6. Describe the use of the TagHelperOutput class and the TagBuilder
class to add an HTML element before or after the tag helper
element.
[HtmlAttributeName("my-max-number")]
public int Max { get; set; }
output.Content.AppendHtml(option);
}
}
}
[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewCtx { get; set; }
// create link
output.BuildLink(url, linkClasses);
output.Content.SetContent(Number.ToString());
}
}
return View(vm);
}
return View(vm);
}
[HtmlAttributeName("my-mark-area-active")]
public bool IsAreaOnly { get; set; }
<main>
<my-temp-message />
@RenderBody()
</main>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js">
</script>
<script src="~/js/site.js" asp-append-version="true"></script>
@RenderSection("Scripts", required: false)
</body>
</html>
<label>Genre: </label>
<vc:genre-drop-down
selected-value="@Model.CurrentRoute.GenreFilter">
</vc:genre-drop-down>
<label>Price: </label>
<vc:price-drop-down
selected-value="@Model.CurrentRoute.PriceFilter">
</vc:price-drop-down>