Visual Studio .net core tag helpers not working

后端 未结 9 2441
暗喜
暗喜 2021-02-19 00:49

Well, lets get down to it. I\'m using Visual Studio 2015 and ASP.NET core tag helpers have completely stopped working, no idea why as I\'ve not changed anything. I was in work o

相关标签:
9条回答
  • 2021-02-19 01:33

    Here's good contender for the dumbest way to cause Tag Helpers to ignore you in disdain. Try commenting out an individual HTML attribute...

    <input id='@Model.InputId.Records[0].TenantId'
            class='class-1'
            @*class='class-2'   THIS WILL NEGATE THE asp-for ATTRIBUTE BELOW *@
            asp-for="@Model.Records[0].TenantId"
            type='text'
            placeholder='Required.' />
    
    0 讨论(0)
  • 2021-02-19 01:39

    I noticed that the tag helpers only helped for some views as @MayBeNextTime kindly informed us. Although, @Menace advises to add duplicates of the _ViewImports file to every Area you have views in, in order for the tag helpers to work for every view you have in your application, I found that by moving the _ViewImports file to the main application folder (right next to/or above Program.cs , Startup.cs , appsettings.json in your Solution Explorer) that you will achieve ubiquitous tag helpers' functionality without creating duplicate files in your app.

    Check this out:

    https://docs.microsoft.com/en-us/aspnet/core/mvc/views/layout?view=aspnetcore-2.2

    It says:

    A _ViewImports.cshtml file can be placed within any folder, in which case it will only be applied to pages or views within that folder and its subfolders.

    0 讨论(0)
  • 2021-02-19 01:43

    If you are experiencing the same problem when using Areas, add the _ViewImports file to the Views folder of your Area

    0 讨论(0)
提交回复
热议问题