I have a Html Helper method that checks if a Section is defined and if not it should write out a partial file.
For this method I can pass a long string (the partial is rather big) or maybe I could pass the actual method @Html.RenderPartial(..) which would be much more efficient in my opinion (or is it negligible?).
Although I dont know how I could pass the @Html.RenderPartial(..) method as a parameter in the following function? Should I create a delegate?
public static HelperResult RenderSectionEx(this WebPageBase webPage,
string name, ??? defaultContents)
{
if (webPage.IsSectionDefined(name))
return webPage.RenderSection(name);
else return defaultContents(null);
}
Usage:
@this.RenderSectionEx("MetaTags", Html.Partial("~/Views/Shared/Partials/MetaTags.cshtml"))
What would be nice is to have the ability to pass both strings or a function in this method so I could pass small strings, for eg;
@this.RenderSectionEx("Title", @<h1>blah</h1>)
@this.RenderSectionEx("MetaTags", Html.Partial("~/Views/Shared/Partials/MetaTags.cshtml"))