Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volkanceylan/19fd115cfa2a02fe0b0a396f9551352f to your computer and use it in GitHub Desktop.
Save volkanceylan/19fd115cfa2a02fe0b0a396f9551352f to your computer and use it in GitHub Desktop.
public static void AppendSection(this IDictionary<string, RenderAsyncDelegate> args, string key, Func<dynamic, dynamic> text)
{
if (!args.ContainsKey(key))
{
args.Add(key, (async textWriter =>
{
await text("").WriteAction(textWriter);
}));
}
else {
args[key] += (async textWriter =>
{
await text("").WriteAction(textWriter);
});
}
}
public static void AppendSection(this IDictionary<string, RenderAsyncDelegate> args, string key, Task<IHtmlContent> contentTask)
{
if (!args.ContainsKey(key))
{
args.Add(key, (async textWriter =>
{
var content = await contentTask;
content.WriteTo(textWriter, Microsoft.Extensions.WebEncoders.HtmlEncoder.Default);
}));
}
else {
args[key] += (async textWriter =>
{
var content = await contentTask;
content.WriteTo(textWriter, Microsoft.Extensions.WebEncoders.HtmlEncoder.Default);
});
}
}
Usage
this.SectionWriters.AppendSection("sectionName",@<script>
</script>
);
SectionWriters.AppendSection("sectionName", Html.PartialAsync("PartialViewName"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment