Last active
January 8, 2016 12:37
-
-
Save tboby/8b2587a94a6e494d955e to your computer and use it in GitHub Desktop.
Helper Example
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
@functions | |
{ | |
public static HelperResult ValidatedElementFor<TModel, TProperty>(HtmlHelper<TModel> html, Expression<Func<TModel, TProperty>> expr, object editorHtmlAttributes = null) | |
{ | |
var defaultHtmlAttributes = new { @class = "form-control" }; | |
var combinedHtmlAttributes = html.MergeHtmlAttributes(defaultHtmlAttributes, editorHtmlAttributes); | |
return ValidatedElement(html.ValidationErrorFor(expr, " has-error", " has-success"), html.LabelFor(expr, htmlAttributes: new { @class = "control-label col-sm-3" }), html.EditorFor(expr, new { htmlAttributes= combinedHtmlAttributes}), html.ValidationMessageFor(expr, "", new { @class = "text-danger" })); | |
} | |
} | |
@helper ValidatedElement(MvcHtmlString error, MvcHtmlString label, MvcHtmlString editor, MvcHtmlString message) | |
{ | |
<div class="form-group has-feedback@(error)"> | |
@label | |
<div class="col-sm-9"> | |
@editor | |
<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span> | |
<span class="glyphicon glyphicon-info-sign form-control-feedback" aria-hidden="true"></span> | |
<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span> | |
@message | |
</div> | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment