Created
January 4, 2013 12:09
-
-
Save ChrisMcKee/4452168 to your computer and use it in GitHub Desktop.
usage i.e. String Editor Template...
usage ala first comment
This file contains hidden or 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.Linq.Expressions; | |
| using System.Web; | |
| using System.Web.Mvc; | |
| public static class ControlGroupExtensions | |
| { | |
| public static IHtmlString BeginControlGroupFor<T>(this HtmlHelper<T> html, | |
| Expression<Func<T, object>> modelProperty) | |
| { | |
| var controlGroupWrapper = new TagBuilder("div"); | |
| controlGroupWrapper.AddCssClass("control-group"); | |
| var partialFieldName = ExpressionHelper.GetExpressionText(modelProperty); | |
| var fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(partialFieldName); | |
| if (!html.ViewData.ModelState.IsValidField(fullHtmlFieldName)) | |
| { | |
| controlGroupWrapper.AddCssClass("error"); | |
| } | |
| var openingTag = controlGroupWrapper.ToString(TagRenderMode.StartTag); | |
| return MvcHtmlString.Create(openingTag); | |
| } | |
| public static IHtmlString EndControlGroup(this HtmlHelper html) | |
| { | |
| return MvcHtmlString.Create("</div>"); | |
| } | |
| } |
Author
ChrisMcKee
commented
Jan 4, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment