Skip to content

Instantly share code, notes, and snippets.

@sebnilsson
Last active September 30, 2015 19:47
Show Gist options
  • Save sebnilsson/5c6da9be1924834daca3 to your computer and use it in GitHub Desktop.
Save sebnilsson/5c6da9be1924834daca3 to your computer and use it in GitHub Desktop.
RenderSection with Default Content
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