Custom tag helper not working
up vote
14
down vote
favorite
I followed a few guides on creating a custom tag helper for ASP Core.
This is my helper:
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
namespace ToolControlSystem.TagHelpers
{
[HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
public class DescriptionTagHelper : TagHelper
{
private const string DescriptionAttributeName = "asp-for";
[HtmlAttributeName(DescriptionAttributeName)]
public ModelExpression Model { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
base.Process(context, output);
var description = GetDescription(Model.ModelExplorer);
output.TagName = "span";
output.TagMode = TagMode.StartTagAndEndTag;
output.Content.SetContent(description);
}
private string GetDescription(ModelExplorer modelExplorer)
{
string description;
description = modelExplorer.Metadata.Placeholder;
if (String.IsNullOrWhiteSpace(description))
{
description = modelExplorer.Metadata.Description;
}
return description;
}
}
}
I drop this in _ViewImports.cshtml
: @addTagHelper *, ToolConstrolSystem.TagHelpers
Annnndd... nothing. No intellisense, no tag replacing...
Any ideas?
c# asp.net-core model asp.net-core-tag-helpers
add a comment |
up vote
14
down vote
favorite
I followed a few guides on creating a custom tag helper for ASP Core.
This is my helper:
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
namespace ToolControlSystem.TagHelpers
{
[HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
public class DescriptionTagHelper : TagHelper
{
private const string DescriptionAttributeName = "asp-for";
[HtmlAttributeName(DescriptionAttributeName)]
public ModelExpression Model { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
base.Process(context, output);
var description = GetDescription(Model.ModelExplorer);
output.TagName = "span";
output.TagMode = TagMode.StartTagAndEndTag;
output.Content.SetContent(description);
}
private string GetDescription(ModelExplorer modelExplorer)
{
string description;
description = modelExplorer.Metadata.Placeholder;
if (String.IsNullOrWhiteSpace(description))
{
description = modelExplorer.Metadata.Description;
}
return description;
}
}
}
I drop this in _ViewImports.cshtml
: @addTagHelper *, ToolConstrolSystem.TagHelpers
Annnndd... nothing. No intellisense, no tag replacing...
Any ideas?
c# asp.net-core model asp.net-core-tag-helpers
add a comment |
up vote
14
down vote
favorite
up vote
14
down vote
favorite
I followed a few guides on creating a custom tag helper for ASP Core.
This is my helper:
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
namespace ToolControlSystem.TagHelpers
{
[HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
public class DescriptionTagHelper : TagHelper
{
private const string DescriptionAttributeName = "asp-for";
[HtmlAttributeName(DescriptionAttributeName)]
public ModelExpression Model { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
base.Process(context, output);
var description = GetDescription(Model.ModelExplorer);
output.TagName = "span";
output.TagMode = TagMode.StartTagAndEndTag;
output.Content.SetContent(description);
}
private string GetDescription(ModelExplorer modelExplorer)
{
string description;
description = modelExplorer.Metadata.Placeholder;
if (String.IsNullOrWhiteSpace(description))
{
description = modelExplorer.Metadata.Description;
}
return description;
}
}
}
I drop this in _ViewImports.cshtml
: @addTagHelper *, ToolConstrolSystem.TagHelpers
Annnndd... nothing. No intellisense, no tag replacing...
Any ideas?
c# asp.net-core model asp.net-core-tag-helpers
I followed a few guides on creating a custom tag helper for ASP Core.
This is my helper:
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
namespace ToolControlSystem.TagHelpers
{
[HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
public class DescriptionTagHelper : TagHelper
{
private const string DescriptionAttributeName = "asp-for";
[HtmlAttributeName(DescriptionAttributeName)]
public ModelExpression Model { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
base.Process(context, output);
var description = GetDescription(Model.ModelExplorer);
output.TagName = "span";
output.TagMode = TagMode.StartTagAndEndTag;
output.Content.SetContent(description);
}
private string GetDescription(ModelExplorer modelExplorer)
{
string description;
description = modelExplorer.Metadata.Placeholder;
if (String.IsNullOrWhiteSpace(description))
{
description = modelExplorer.Metadata.Description;
}
return description;
}
}
}
I drop this in _ViewImports.cshtml
: @addTagHelper *, ToolConstrolSystem.TagHelpers
Annnndd... nothing. No intellisense, no tag replacing...
Any ideas?
c# asp.net-core model asp.net-core-tag-helpers
c# asp.net-core model asp.net-core-tag-helpers
edited May 11 at 22:47
Camilo Terevinto
17.6k63464
17.6k63464
asked Jan 15 at 22:23
Matthew Goulart
993723
993723
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
38
down vote
accepted
You need to provide only assembly name in the view imports file.
_ViewImports.cshtml:
@addTagHelper *, ToolConstrolSystem
5
This was really annoying. Thanks for the answear.
– Edgar Salazar
Apr 6 at 16:52
4
Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
– Mikhail
Apr 21 at 10:17
2
Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
– qJake
Jun 12 at 20:54
The assembly name!! I had the namespace. 3 hours lost until I read this.
– Alpha75
Nov 28 at 11:54
add a comment |
up vote
3
down vote
See Managing Tag Helper scope
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, AuthoringTagHelpers
The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
38
down vote
accepted
You need to provide only assembly name in the view imports file.
_ViewImports.cshtml:
@addTagHelper *, ToolConstrolSystem
5
This was really annoying. Thanks for the answear.
– Edgar Salazar
Apr 6 at 16:52
4
Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
– Mikhail
Apr 21 at 10:17
2
Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
– qJake
Jun 12 at 20:54
The assembly name!! I had the namespace. 3 hours lost until I read this.
– Alpha75
Nov 28 at 11:54
add a comment |
up vote
38
down vote
accepted
You need to provide only assembly name in the view imports file.
_ViewImports.cshtml:
@addTagHelper *, ToolConstrolSystem
5
This was really annoying. Thanks for the answear.
– Edgar Salazar
Apr 6 at 16:52
4
Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
– Mikhail
Apr 21 at 10:17
2
Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
– qJake
Jun 12 at 20:54
The assembly name!! I had the namespace. 3 hours lost until I read this.
– Alpha75
Nov 28 at 11:54
add a comment |
up vote
38
down vote
accepted
up vote
38
down vote
accepted
You need to provide only assembly name in the view imports file.
_ViewImports.cshtml:
@addTagHelper *, ToolConstrolSystem
You need to provide only assembly name in the view imports file.
_ViewImports.cshtml:
@addTagHelper *, ToolConstrolSystem
edited Nov 22 at 2:30
answered Jan 16 at 0:39
Anuraj
12.7k33663
12.7k33663
5
This was really annoying. Thanks for the answear.
– Edgar Salazar
Apr 6 at 16:52
4
Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
– Mikhail
Apr 21 at 10:17
2
Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
– qJake
Jun 12 at 20:54
The assembly name!! I had the namespace. 3 hours lost until I read this.
– Alpha75
Nov 28 at 11:54
add a comment |
5
This was really annoying. Thanks for the answear.
– Edgar Salazar
Apr 6 at 16:52
4
Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
– Mikhail
Apr 21 at 10:17
2
Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
– qJake
Jun 12 at 20:54
The assembly name!! I had the namespace. 3 hours lost until I read this.
– Alpha75
Nov 28 at 11:54
5
5
This was really annoying. Thanks for the answear.
– Edgar Salazar
Apr 6 at 16:52
This was really annoying. Thanks for the answear.
– Edgar Salazar
Apr 6 at 16:52
4
4
Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
– Mikhail
Apr 21 at 10:17
Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
– Mikhail
Apr 21 at 10:17
2
2
Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
– qJake
Jun 12 at 20:54
Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
– qJake
Jun 12 at 20:54
The assembly name!! I had the namespace. 3 hours lost until I read this.
– Alpha75
Nov 28 at 11:54
The assembly name!! I had the namespace. 3 hours lost until I read this.
– Alpha75
Nov 28 at 11:54
add a comment |
up vote
3
down vote
See Managing Tag Helper scope
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, AuthoringTagHelpers
The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.
add a comment |
up vote
3
down vote
See Managing Tag Helper scope
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, AuthoringTagHelpers
The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.
add a comment |
up vote
3
down vote
up vote
3
down vote
See Managing Tag Helper scope
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, AuthoringTagHelpers
The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.
See Managing Tag Helper scope
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, AuthoringTagHelpers
The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.
answered Jun 13 at 20:08
RickAndMSFT
10.6k53954
10.6k53954
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48271514%2fcustom-tag-helper-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown