Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Tag helpers not working

I have an issue with tag helpers. All I want to do is create a form that posts data to the controller - basic enough I thought but it doesnt work in my project.

I create a brand new asp.net core web application with default setup and it works there but my project refuses to recognise the tags and act accordingly. Notably the markup doesnt highlight the same or provide info when hovered over so some ref or something fundamental is missing, can anyone advise.

*Default project working with correct highlights enter image description here

*My project - not highlighting the code right or working. Project.json is the exact same so I have no idea whats missing. enter image description here

like image 493
Monolithcode Avatar asked Jun 07 '16 06:06

Monolithcode


1 Answers

FOUND IT! Microsoft like to change things. So, MVC 6 (asp.net core ...etc) can make use of a _ViewImports.cshtml file in the views folder (feel free to add it yourself if you like me made a project before this existed).

This acts like global import file, and to make the tag helpers available in all your views, you need to add reference here.

Mine now looks like this:

@using Mobile.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

And boom - tags look correct and its work as expected.

like image 85
Monolithcode Avatar answered Sep 29 '22 14:09

Monolithcode