This repository was archived by the owner on Dec 14, 2018. It is now read-only.
File tree 1 file changed +44
-0
lines changed
src/Microsoft.AspNet.Mvc.TagHelpers
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2
+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
+
4
+ using Microsoft . AspNet . Mvc . Rendering ;
5
+ using Microsoft . AspNet . Razor . Runtime . TagHelpers ;
6
+ using Microsoft . AspNet . Razor . TagHelpers ;
7
+
8
+ namespace Microsoft . AspNet . Mvc . TagHelpers
9
+ {
10
+ /// <summary>
11
+ /// <see cref="ITagHelper"/> implementation targeting <span> elements with <c>validation-for</c> attributes.
12
+ /// </summary>
13
+ [ TagName ( "span" ) ]
14
+ [ ContentBehavior ( ContentBehavior . Modify ) ]
15
+ public class ValidationMessageTagHelper : TagHelper
16
+ {
17
+ [ Activate ]
18
+ private ViewContext ViewContext { get ; set ; }
19
+
20
+ [ Activate ]
21
+ private IHtmlGenerator Generator { get ; set ; }
22
+
23
+ /// <summary>
24
+ /// Name to be validated on the current model.
25
+ /// </summary>
26
+ [ HtmlAttributeName ( "validation-for" ) ]
27
+ public ModelExpression For { get ; set ; }
28
+
29
+ /// <inheritdoc />
30
+ public override void Process ( TagHelperContext context , TagHelperOutput output )
31
+ {
32
+ if ( For != null )
33
+ {
34
+ var tagBuilder = Generator . GenerateValidationMessage ( ViewContext ,
35
+ For . Name ,
36
+ message : output . Content ,
37
+ tag : output . TagName ,
38
+ htmlAttributes : null ) ;
39
+
40
+ output . Merge ( tagBuilder ) ;
41
+ }
42
+ }
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments