This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a09f0b
commit 00054f3
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/Microsoft.AspNet.Mvc.TagHelpers/ValidationMessageTagHelper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNet.Mvc.Rendering; | ||
using Microsoft.AspNet.Razor.Runtime.TagHelpers; | ||
using Microsoft.AspNet.Razor.TagHelpers; | ||
|
||
namespace Microsoft.AspNet.Mvc.TagHelpers | ||
{ | ||
/// <summary> | ||
/// <see cref="ITagHelper"/> implementation targeting <span> elements with <c>validation-for</c> attributes. | ||
/// </summary> | ||
[TagName("span")] | ||
[ContentBehavior(ContentBehavior.Modify)] | ||
public class ValidationMessageTagHelper : TagHelper | ||
{ | ||
[Activate] | ||
private ViewContext ViewContext { get; set; } | ||
|
||
[Activate] | ||
private IHtmlGenerator Generator { get; set; } | ||
|
||
/// <summary> | ||
/// Name to be validated on the current model. | ||
/// </summary> | ||
[HtmlAttributeName("validation-for")] | ||
public ModelExpression For { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public override void Process(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
if (For != null) | ||
{ | ||
var tagBuilder = Generator.GenerateValidationMessage(ViewContext, | ||
For.Name, | ||
message: output.Content, | ||
tag: output.TagName, | ||
htmlAttributes: null); | ||
|
||
output.Merge(tagBuilder); | ||
} | ||
} | ||
} | ||
} |