Skip to content

Instantly share code, notes, and snippets.

Avatar

Scott Addie scottaddie

View GitHub Profile
@scottaddie
scottaddie / _ViewImports.cshtml
Created Mar 3, 2018
Using the addTagHelper directive to register the LinkButtonTagHelper
View _ViewImports.cshtml
@addTagHelper *, TagHelperSuite
@scottaddie
scottaddie / Index.cshtml
Created Mar 3, 2018
LinkButtonTagHelper markup in ASP.NET Core
View Index.cshtml
<form asp-page-handler="Post">
<link-button>Test Link</link-button>
</form>
@scottaddie
scottaddie / Default.aspx
Created Mar 3, 2018
Web Forms LinkButton sample in Default.aspx
View Default.aspx
<asp:LinkButton ID="lbtnSubmit" runat="server" PostBackUrl="~/About.aspx" Text="Submit Form" />
@scottaddie
scottaddie / Index.cshtml
Created Mar 3, 2018
Index Razor Page CSHTML file in an ASP.NET Core 2.x app
View Index.cshtml
<form method="post">
<button asp-page="/Index" asp-page-handler="Post">Submit Form</button>
</form>
@scottaddie
scottaddie / Index.cshtml.cs
Created Mar 3, 2018
Index page model in an ASP.NET Core 2.x Razor Pages app
View Index.cshtml.cs
public class IndexModel : PageModel
{
public void OnGet()
{
}
public void OnPost()
{
}
}
@scottaddie
scottaddie / LinkButtonTagHelper.cs
Created Mar 3, 2018
Custom Tag Helper for rendering a LinkButton-like anchor in ASP.NET Core
View LinkButtonTagHelper.cs
[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();");
@scottaddie
scottaddie / CardTagHelper.cs
Last active Jan 30, 2017
Example of adding a card object to the Cards collection in the context class
View CardTagHelper.cs
// Fetch the context, so that we can add the Card object to the Cards collection
var handContext = (HandContext)context.Items[typeof(HandTagHelper)];
handContext.Cards.Add(new Card { Rank = rank, Suit = suit });
@scottaddie
scottaddie / HandContext.cs
Last active Jan 30, 2017
Example of custom context class used to store cards collection
View HandContext.cs
public class HandContext
{
public List<Card> Cards { get; set; } = new List<Card>();
}
@scottaddie
scottaddie / _Card.cshtml
Created Jan 30, 2017
Partial view containing card tag helper HTML
View _Card.cshtml
@model TagHelpersDemo.Views.Shared.Partials.CardViewModel
<img src="images/@(Model.PlayerName).png" alt="avatar" class="center-block" />
<div class="text-center">
<h2 class="@Model.SuitColorClass">
<strong>@Html.Raw(Model.SuitCharacterCode)</strong>
</h2>
<p>@Model.Rank</p>
</div>
@scottaddie
scottaddie / CardTagHelper.cs
Created Jan 30, 2017
CardTagHelper refactored to read HTML from partial view
View CardTagHelper.cs
var content = await _html.PartialAsync("~/Views/Shared/Partials/_Card.cshtml", model);
output.Content.SetHtmlContent(content);
You can’t perform that action at this time.