Skip to content

Instantly share code, notes, and snippets.

@jbogard
Created July 25, 2014 13:26
Show Gist options
  • Save jbogard/8b53aff35ddf043b5b5f to your computer and use it in GitHub Desktop.
Save jbogard/8b53aff35ddf043b5b5f to your computer and use it in GitHub Desktop.
public static HtmlTag FormBlock<T>(this HtmlHelper<T> helper,
Expression<Func<T, object>> expression,
Action<HtmlTag> labelModifier = null,
Action<HtmlTag> inputBlockModifier = null,
Action<HtmlTag> inputModifier = null,
Action<HtmlTag> validatorModifier = null
) where T : class
{
labelModifier = labelModifier ?? (_ => { });
inputBlockModifier = inputBlockModifier ?? (_ => { });
var divTag = new HtmlTag("div");
divTag.AddClass("form-group");
var labelTag = helper.Label(expression);
labelModifier(labelTag);
var inputBlockTag = helper.InputBlock(
expression,
inputModifier,
validatorModifier);
inputBlockModifier(inputBlockTag);
divTag.Append(labelTag);
divTag.Append(inputBlockTag);
return divTag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment