A group of us who have been exploring MVC 6 Tag Helpers have created a repository of Tag Helper Samples. The repository contains a set of real world samples that can help you understand how to build your own custom tag helpers.
So far, we have been focusing on Tag Helpers that make it easier to use various Bootstrap components. We chose Bootstrap because Bootstrap components are often verbose and it can be easy to miss a particular class or a specific attribute. I find that this is especially when you consider all the accessibility aria-* attributes. So far, we have implemented tag helpers for Bootstrap Alerts, Progress Bars and most recently Modals.
Alert
The alert tag helper, contributed by Rick Strahl, makes it easy to display Bootstrap alerts containing Font-Awesome icons.
1 | <alert message="Payment has been processed." icon="success"> |
Will output the following HTML:
1 | <div class="alert alert-success" role="alert"> |
Progress Bar
Displaying a progress bar in Bootstrap is a rather verbose set of elements and attributes:
1 | <div class="progress"> |
The progress bar tag helper provides a much cleaner syntax:
1 | <div bs-progress-value="66"> |
Modal
Bootstrap modals are also rather convoluted items. The simplest possible modal consists of too many nested divs and in my opinion is hard to read:
1 | <div class="modal fade"> |
The same modal using the modal tag helper is much easier to read and will produce the same output:
1 | <modal id="simpleModal" title="Modal Title" > |
Wrapping it up
Feel free to browse the sample code or view them in action on Azure. If you have ideas for other Tag Helpers, feel free to log an issue in the repo. Better yet, you could also submit a pull request.
A big thank you to Rick Anderson for suggesting this and getting us started and to Rick Strahl for contributing.