Created
February 4, 2017 14:13
-
-
Save volkanceylan/19fd115cfa2a02fe0b0a396f9551352f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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