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

Commit 408e108

Browse files
committed
Add TextAreaTagHelper and Microsoft.AspNet.Mvc.TagHelpers project
- rest of #1243 and all of #1244 - needs a few utility methods for copying `TagBuilder` to `TagHelperOutput` - but works as-is
1 parent 056baf4 commit 408e108

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

Mvc.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.WebApi
100100
EndProject
101101
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TagHelperSample.Web", "samples\TagHelperSample.Web\TagHelperSample.Web.kproj", "{2223120F-D675-40DA-8CD8-11DC14A0B2C7}"
102102
EndProject
103+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TagHelpers", "src\Microsoft.AspNet.Mvc.TagHelpers\Microsoft.AspNet.Mvc.TagHelpers.kproj", "{B2347320-308E-4D2B-AEC8-005DFA68B0C9}"
104+
EndProject
103105
Global
104106
GlobalSection(SolutionConfigurationPlatforms) = preSolution
105107
Debug|Any CPU = Debug|Any CPU
@@ -530,6 +532,16 @@ Global
530532
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
531533
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
532534
{2223120F-D675-40DA-8CD8-11DC14A0B2C7}.Release|x86.ActiveCfg = Release|Any CPU
535+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
536+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
537+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
538+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
539+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|x86.ActiveCfg = Debug|Any CPU
540+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
541+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Release|Any CPU.Build.0 = Release|Any CPU
542+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
543+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Release|Mixed Platforms.Build.0 = Release|Any CPU
544+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Release|x86.ActiveCfg = Release|Any CPU
533545
EndGlobalSection
534546
GlobalSection(SolutionProperties) = preSolution
535547
HideSolutionNode = FALSE
@@ -578,5 +590,6 @@ Global
578590
{B2B7BC91-688E-4C1E-A71F-CE948D958DDF} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
579591
{5DE8E4D9-AACD-4B5F-819F-F091383FB996} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
580592
{2223120F-D675-40DA-8CD8-11DC14A0B2C7} = {DAAE4C74-D06F-4874-A166-33305D2643CE}
593+
{B2347320-308E-4D2B-AEC8-005DFA68B0C9} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
581594
EndGlobalSection
582595
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>b2347320-308e-4d2b-aec8-005dfa68b0c9</ProjectGuid>
11+
<OutputType>Library</OutputType>
12+
<RootNamespace>Microsoft.AspNet.Mvc.TagHelpers</RootNamespace>
13+
</PropertyGroup>
14+
15+
<PropertyGroup>
16+
<SchemaVersion>2.0</SchemaVersion>
17+
</PropertyGroup>
18+
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
19+
</Project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.TagHelpers;
6+
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
7+
8+
namespace Microsoft.AspNet.Mvc.TagHelpers
9+
{
10+
/// <summary>
11+
/// <see cref="ITagHelper"/> implementation targeting &lt;textarea&gt; elements.
12+
/// </summary>
13+
[ContentBehavior(ContentBehavior.Replace)]
14+
public class TextAreaTagHelper : TagHelper
15+
{
16+
[Activate]
17+
private IHtmlGenerator Generator { get; set; }
18+
19+
[Activate]
20+
private ViewContext ViewContext { get; set; }
21+
22+
/// <summary>
23+
/// An expression to be evaluated against the current model.
24+
/// </summary>
25+
public ModelExpression For { get; set; }
26+
27+
/// <inheritdoc />
28+
/// <remarks>Does nothing unless user binds "for" attribute in Razor source.</remarks>
29+
public override void Process(TagHelperContext context, TagHelperOutput output)
30+
{
31+
if (For != null)
32+
{
33+
var tagBuilder = Generator.GenerateTextArea(
34+
ViewContext,
35+
For.Metadata,
36+
For.Name,
37+
rows: 0,
38+
columns: 0,
39+
htmlAttributes: null);
40+
41+
if (tagBuilder != null)
42+
{
43+
output.SelfClosing = false;
44+
45+
// TODO: Use infrastructure from PR #1322 to copy from tagBuilder.
46+
foreach (var attribute in tagBuilder.Attributes)
47+
{
48+
if (!output.Attributes.ContainsKey(attribute.Key))
49+
{
50+
output.Attributes.Add(attribute.Key, attribute.Value);
51+
}
52+
}
53+
54+
output.Content = tagBuilder.InnerHtml;
55+
output.TagName = tagBuilder.TagName;
56+
}
57+
}
58+
}
59+
}
60+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "6.0.0-*",
3+
"compilationOptions": {
4+
"warningsAsErrors": true
5+
},
6+
"dependencies": {
7+
"Microsoft.AspNet.Mvc.Razor": ""
8+
},
9+
"frameworks": {
10+
"aspnet50": {
11+
"dependencies": {}
12+
},
13+
"aspnetcore50": {
14+
"dependencies": {
15+
"System.Runtime": "4.0.20.0"
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)