Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Add ValidationMessage TagHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
NTaylorMullen committed Oct 12, 2014
1 parent 761faf8 commit 4473a33
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Microsoft.AspNet.Mvc.TagHelpers/ValidationMessageTagHelper.cs
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 &lt;span&gt; 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>
/// An 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);
}
}
}
}

0 comments on commit 4473a33

Please sign in to comment.