Skip to content

Instantly share code, notes, and snippets.

View scottaddie's full-sized avatar
💭
.NET 💜 Azure

Scott Addie scottaddie

💭
.NET 💜 Azure
View GitHub Profile
@scottaddie
scottaddie / _ViewImports.cshtml
Created March 3, 2018 19:32
Using the addTagHelper directive to register the LinkButtonTagHelper
@addTagHelper *, TagHelperSuite
@scottaddie
scottaddie / Index.cshtml
Created March 3, 2018 16:51
LinkButtonTagHelper markup in ASP.NET Core
<form asp-page-handler="Post">
<link-button>Test Link</link-button>
</form>
@scottaddie
scottaddie / Default.aspx
Created March 3, 2018 16:49
Web Forms LinkButton sample in Default.aspx
<asp:LinkButton ID="lbtnSubmit" runat="server" PostBackUrl="~/About.aspx" Text="Submit Form" />
@scottaddie
scottaddie / Index.cshtml
Created March 3, 2018 16:47
Index Razor Page CSHTML file in an ASP.NET Core 2.x app
<form method="post">
<button asp-page="/Index" asp-page-handler="Post">Submit Form</button>
</form>
@scottaddie
scottaddie / Index.cshtml.cs
Created March 3, 2018 16:46
Index page model in an ASP.NET Core 2.x Razor Pages app
public class IndexModel : PageModel
{
public void OnGet()
{
}
public void OnPost()
{
}
}
@scottaddie
scottaddie / LinkButtonTagHelper.cs
Created March 3, 2018 16:33
Custom Tag Helper for rendering a LinkButton-like anchor in ASP.NET Core
[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 January 30, 2017 15:46
Example of adding a card object to the Cards collection in the context class
// 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 January 30, 2017 15:43
Example of custom context class used to store cards collection
public class HandContext
{
public List<Card> Cards { get; set; } = new List<Card>();
}
@scottaddie
scottaddie / _Card.cshtml
Created January 30, 2017 13:50
Partial view containing card tag helper HTML
@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 January 30, 2017 04:19
CardTagHelper refactored to read HTML from partial view
var content = await _html.PartialAsync("~/Views/Shared/Partials/_Card.cshtml", model);
output.Content.SetHtmlContent(content);