locked
Reusable button - Custom tag helper? RRS feed

  • Question

  • User-29703693 posted

    I have this button on about a dozen of my pages:

    <button type="button" class="btn btn-outline-primary btn-back" onclick="location.href='/Controller/Action'">Button text</button>
    

    The text of the button will change along with the link but everything else should be the same.  Some options I'm thinking about doing are:

    1. Just writing the html  ~12 times.  
    2. Putting something like this in my _layout page:
    @if (ViewBag.Button != null)
    {
    <button type="button" class="btn btn-outline-primary btn-back" onclick="location.href='@ViewBag.ButtonLink'">@ViewBag.Button</button>
    }
    

    3. Creating a custom tag helper for it

    4. ???

    What would you do?  

    Saturday, April 18, 2020 8:48 PM

Answers