ASP.NET: tag helper do not work. Where start debugging?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm reading Adam Freeman "Pro ASP.NET Core MVC 2" book and following the book's project SportsStore.
I'm having problem with tag helpers, when I'm running the project the navigation links in the bottom do not work, instead I see a tag helper in page source:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>SportsStore V2</title>
</head>
<body>
<div>
<div>
<h3>Kayak</h3>
A boat for one person
<h4>275,00 €</h4>
</div>
<div>
<h3>Lifejacket</h3>
Protective and fashionable
<h4>48,95 €</h4>
</div>
<div>
<h3>Soccer Ball</h3>
FIFA-approved size and weight
<h4>19,50 €</h4>
</div>
<div>
<h3>Corner Flags</h3>
Give your playing field a professional touch
<h4>34,95 €</h4>
</div>
<div page-model="SportsStoreApp.Models.ViewModels.PagingInfo" page-action="List"></div>
</div>
</body>
</html>
The code of List.cshtml
@model ProductListViewModel
@foreach (var p in Model.Products)
{
<div>
<h3>@p.Name</h3>
@p.Description
<h4>@p.Price.ToString("c")</h4>
</div>
}
<div page-model="@Model.PagingInfo" page-action="List"></div>
The code of PageLinkTagHelper class
namespace SportsStoreApp.Infrastructure
{
[HtmlTargetElement("div", Attributes = "page-model")]
public class PageLinkTagHelper : TagHelper
{
private IUrlHelperFactory urlHelperFactory;
public PageLinkTagHelper(IUrlHelperFactory helperFactory)
{
urlHelperFactory = helperFactory;
}
[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }
public PagingInfo PageModel { get; set; }
public string PageAction { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext);
TagBuilder result = new TagBuilder("div");
for (int i = 1; i <= PageModel.TotalPages; i++)
{
TagBuilder tag = new TagBuilder("a");
tag.Attributes["href"] = urlHelper.Action(PageAction, new {productPage = i});
tag.InnerHtml.Append(i.ToString());
result.InnerHtml.AppendHtml(tag);
}
output.Content.AppendHtml(result.InnerHtml);
}
}
}
As I don't have experience with ASP.NET nor MVC, I don't understand how should I start to troubleshoot this problem?
PS I tried to rewrite from scratch, no result.
c# asp.net asp.net-mvc
add a comment |
I'm reading Adam Freeman "Pro ASP.NET Core MVC 2" book and following the book's project SportsStore.
I'm having problem with tag helpers, when I'm running the project the navigation links in the bottom do not work, instead I see a tag helper in page source:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>SportsStore V2</title>
</head>
<body>
<div>
<div>
<h3>Kayak</h3>
A boat for one person
<h4>275,00 €</h4>
</div>
<div>
<h3>Lifejacket</h3>
Protective and fashionable
<h4>48,95 €</h4>
</div>
<div>
<h3>Soccer Ball</h3>
FIFA-approved size and weight
<h4>19,50 €</h4>
</div>
<div>
<h3>Corner Flags</h3>
Give your playing field a professional touch
<h4>34,95 €</h4>
</div>
<div page-model="SportsStoreApp.Models.ViewModels.PagingInfo" page-action="List"></div>
</div>
</body>
</html>
The code of List.cshtml
@model ProductListViewModel
@foreach (var p in Model.Products)
{
<div>
<h3>@p.Name</h3>
@p.Description
<h4>@p.Price.ToString("c")</h4>
</div>
}
<div page-model="@Model.PagingInfo" page-action="List"></div>
The code of PageLinkTagHelper class
namespace SportsStoreApp.Infrastructure
{
[HtmlTargetElement("div", Attributes = "page-model")]
public class PageLinkTagHelper : TagHelper
{
private IUrlHelperFactory urlHelperFactory;
public PageLinkTagHelper(IUrlHelperFactory helperFactory)
{
urlHelperFactory = helperFactory;
}
[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }
public PagingInfo PageModel { get; set; }
public string PageAction { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext);
TagBuilder result = new TagBuilder("div");
for (int i = 1; i <= PageModel.TotalPages; i++)
{
TagBuilder tag = new TagBuilder("a");
tag.Attributes["href"] = urlHelper.Action(PageAction, new {productPage = i});
tag.InnerHtml.Append(i.ToString());
result.InnerHtml.AppendHtml(tag);
}
output.Content.AppendHtml(result.InnerHtml);
}
}
}
As I don't have experience with ASP.NET nor MVC, I don't understand how should I start to troubleshoot this problem?
PS I tried to rewrite from scratch, no result.
c# asp.net asp.net-mvc
1
did you add your assembly in the viewimports? that always gets me
– Jonesopolis
Nov 16 '18 at 20:45
yes, I've tried to put _ViewImports.cshtml to the same folder as List.cshtml and to the root of Views folder using SportsStoreApp.Models using SportsStoreApp.Models.ViewModels addTagHelper , Microsoft.AspNetCore.Mvc.TagHelpers addTagHelper SportsStoreApp.Infrastructure., SportsStore
– puandr
Nov 17 '18 at 10:24
add a comment |
I'm reading Adam Freeman "Pro ASP.NET Core MVC 2" book and following the book's project SportsStore.
I'm having problem with tag helpers, when I'm running the project the navigation links in the bottom do not work, instead I see a tag helper in page source:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>SportsStore V2</title>
</head>
<body>
<div>
<div>
<h3>Kayak</h3>
A boat for one person
<h4>275,00 €</h4>
</div>
<div>
<h3>Lifejacket</h3>
Protective and fashionable
<h4>48,95 €</h4>
</div>
<div>
<h3>Soccer Ball</h3>
FIFA-approved size and weight
<h4>19,50 €</h4>
</div>
<div>
<h3>Corner Flags</h3>
Give your playing field a professional touch
<h4>34,95 €</h4>
</div>
<div page-model="SportsStoreApp.Models.ViewModels.PagingInfo" page-action="List"></div>
</div>
</body>
</html>
The code of List.cshtml
@model ProductListViewModel
@foreach (var p in Model.Products)
{
<div>
<h3>@p.Name</h3>
@p.Description
<h4>@p.Price.ToString("c")</h4>
</div>
}
<div page-model="@Model.PagingInfo" page-action="List"></div>
The code of PageLinkTagHelper class
namespace SportsStoreApp.Infrastructure
{
[HtmlTargetElement("div", Attributes = "page-model")]
public class PageLinkTagHelper : TagHelper
{
private IUrlHelperFactory urlHelperFactory;
public PageLinkTagHelper(IUrlHelperFactory helperFactory)
{
urlHelperFactory = helperFactory;
}
[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }
public PagingInfo PageModel { get; set; }
public string PageAction { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext);
TagBuilder result = new TagBuilder("div");
for (int i = 1; i <= PageModel.TotalPages; i++)
{
TagBuilder tag = new TagBuilder("a");
tag.Attributes["href"] = urlHelper.Action(PageAction, new {productPage = i});
tag.InnerHtml.Append(i.ToString());
result.InnerHtml.AppendHtml(tag);
}
output.Content.AppendHtml(result.InnerHtml);
}
}
}
As I don't have experience with ASP.NET nor MVC, I don't understand how should I start to troubleshoot this problem?
PS I tried to rewrite from scratch, no result.
c# asp.net asp.net-mvc
I'm reading Adam Freeman "Pro ASP.NET Core MVC 2" book and following the book's project SportsStore.
I'm having problem with tag helpers, when I'm running the project the navigation links in the bottom do not work, instead I see a tag helper in page source:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>SportsStore V2</title>
</head>
<body>
<div>
<div>
<h3>Kayak</h3>
A boat for one person
<h4>275,00 €</h4>
</div>
<div>
<h3>Lifejacket</h3>
Protective and fashionable
<h4>48,95 €</h4>
</div>
<div>
<h3>Soccer Ball</h3>
FIFA-approved size and weight
<h4>19,50 €</h4>
</div>
<div>
<h3>Corner Flags</h3>
Give your playing field a professional touch
<h4>34,95 €</h4>
</div>
<div page-model="SportsStoreApp.Models.ViewModels.PagingInfo" page-action="List"></div>
</div>
</body>
</html>
The code of List.cshtml
@model ProductListViewModel
@foreach (var p in Model.Products)
{
<div>
<h3>@p.Name</h3>
@p.Description
<h4>@p.Price.ToString("c")</h4>
</div>
}
<div page-model="@Model.PagingInfo" page-action="List"></div>
The code of PageLinkTagHelper class
namespace SportsStoreApp.Infrastructure
{
[HtmlTargetElement("div", Attributes = "page-model")]
public class PageLinkTagHelper : TagHelper
{
private IUrlHelperFactory urlHelperFactory;
public PageLinkTagHelper(IUrlHelperFactory helperFactory)
{
urlHelperFactory = helperFactory;
}
[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }
public PagingInfo PageModel { get; set; }
public string PageAction { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext);
TagBuilder result = new TagBuilder("div");
for (int i = 1; i <= PageModel.TotalPages; i++)
{
TagBuilder tag = new TagBuilder("a");
tag.Attributes["href"] = urlHelper.Action(PageAction, new {productPage = i});
tag.InnerHtml.Append(i.ToString());
result.InnerHtml.AppendHtml(tag);
}
output.Content.AppendHtml(result.InnerHtml);
}
}
}
As I don't have experience with ASP.NET nor MVC, I don't understand how should I start to troubleshoot this problem?
PS I tried to rewrite from scratch, no result.
c# asp.net asp.net-mvc
c# asp.net asp.net-mvc
asked Nov 16 '18 at 20:43
puandrpuandr
11
11
1
did you add your assembly in the viewimports? that always gets me
– Jonesopolis
Nov 16 '18 at 20:45
yes, I've tried to put _ViewImports.cshtml to the same folder as List.cshtml and to the root of Views folder using SportsStoreApp.Models using SportsStoreApp.Models.ViewModels addTagHelper , Microsoft.AspNetCore.Mvc.TagHelpers addTagHelper SportsStoreApp.Infrastructure., SportsStore
– puandr
Nov 17 '18 at 10:24
add a comment |
1
did you add your assembly in the viewimports? that always gets me
– Jonesopolis
Nov 16 '18 at 20:45
yes, I've tried to put _ViewImports.cshtml to the same folder as List.cshtml and to the root of Views folder using SportsStoreApp.Models using SportsStoreApp.Models.ViewModels addTagHelper , Microsoft.AspNetCore.Mvc.TagHelpers addTagHelper SportsStoreApp.Infrastructure., SportsStore
– puandr
Nov 17 '18 at 10:24
1
1
did you add your assembly in the viewimports? that always gets me
– Jonesopolis
Nov 16 '18 at 20:45
did you add your assembly in the viewimports? that always gets me
– Jonesopolis
Nov 16 '18 at 20:45
yes, I've tried to put _ViewImports.cshtml to the same folder as List.cshtml and to the root of Views folder using SportsStoreApp.Models using SportsStoreApp.Models.ViewModels addTagHelper , Microsoft.AspNetCore.Mvc.TagHelpers addTagHelper SportsStoreApp.Infrastructure., SportsStore
– puandr
Nov 17 '18 at 10:24
yes, I've tried to put _ViewImports.cshtml to the same folder as List.cshtml and to the root of Views folder using SportsStoreApp.Models using SportsStoreApp.Models.ViewModels addTagHelper , Microsoft.AspNetCore.Mvc.TagHelpers addTagHelper SportsStoreApp.Infrastructure., SportsStore
– puandr
Nov 17 '18 at 10:24
add a comment |
1 Answer
1
active
oldest
votes
I've jumped over to the chapter about TagHelpers and there was written what actually registering taghelper means, it was a naming issue/typo/scope error.
When I registered TagHelper in _ViewsImport, I've used an assembly name from he book - SportsStore. But in my project I wanted to make a difference between Solution name and Project name, so my solution name was SportsSotreV2 and project name (assembly name) SportsStoreApp. So changing
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStore
to
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStoreApp
solved the problem.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53345124%2fasp-net-tag-helper-do-not-work-where-start-debugging%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've jumped over to the chapter about TagHelpers and there was written what actually registering taghelper means, it was a naming issue/typo/scope error.
When I registered TagHelper in _ViewsImport, I've used an assembly name from he book - SportsStore. But in my project I wanted to make a difference between Solution name and Project name, so my solution name was SportsSotreV2 and project name (assembly name) SportsStoreApp. So changing
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStore
to
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStoreApp
solved the problem.
add a comment |
I've jumped over to the chapter about TagHelpers and there was written what actually registering taghelper means, it was a naming issue/typo/scope error.
When I registered TagHelper in _ViewsImport, I've used an assembly name from he book - SportsStore. But in my project I wanted to make a difference between Solution name and Project name, so my solution name was SportsSotreV2 and project name (assembly name) SportsStoreApp. So changing
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStore
to
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStoreApp
solved the problem.
add a comment |
I've jumped over to the chapter about TagHelpers and there was written what actually registering taghelper means, it was a naming issue/typo/scope error.
When I registered TagHelper in _ViewsImport, I've used an assembly name from he book - SportsStore. But in my project I wanted to make a difference between Solution name and Project name, so my solution name was SportsSotreV2 and project name (assembly name) SportsStoreApp. So changing
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStore
to
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStoreApp
solved the problem.
I've jumped over to the chapter about TagHelpers and there was written what actually registering taghelper means, it was a naming issue/typo/scope error.
When I registered TagHelper in _ViewsImport, I've used an assembly name from he book - SportsStore. But in my project I wanted to make a difference between Solution name and Project name, so my solution name was SportsSotreV2 and project name (assembly name) SportsStoreApp. So changing
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStore
to
@addTagHelper SportsStoreApp.Infrastructure.*, SportsStoreApp
solved the problem.
answered Nov 17 '18 at 12:47
puandrpuandr
11
11
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.
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%2f53345124%2fasp-net-tag-helper-do-not-work-where-start-debugging%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
1
did you add your assembly in the viewimports? that always gets me
– Jonesopolis
Nov 16 '18 at 20:45
yes, I've tried to put _ViewImports.cshtml to the same folder as List.cshtml and to the root of Views folder using SportsStoreApp.Models using SportsStoreApp.Models.ViewModels addTagHelper , Microsoft.AspNetCore.Mvc.TagHelpers addTagHelper SportsStoreApp.Infrastructure., SportsStore
– puandr
Nov 17 '18 at 10:24