Last active
September 30, 2015 19:47
-
-
Save sebnilsson/5c6da9be1924834daca3 to your computer and use it in GitHub Desktop.
RenderSection with Default Content
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
using System; | |
using System.Web.WebPages; | |
public static class WebPageBaseExtensions | |
{ | |
public static HelperResult RenderSection(this WebPageBase page, string sectionName, Func<dynamic, HelperResult> defaultContents) | |
{ | |
if (page.IsSectionDefined(sectionName)) | |
{ | |
return page.RenderSection(sectionName); | |
} | |
else | |
{ | |
return defaultContents(null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment