Search code examples
razorrazor-pagestag-helpers

Standard ASP.Net Core tag helpers aren't purple and bold


I have this cshtml, and it doesn't highlight Asp.Net Core tag helpers, like <form>, <input>, <span>, <textarea>. I was partially able to workaround this issue by using @Html.DisplayFor, and it worked. But otherwise I have no idea what's wrong with that. My Visual Studio version is 2017 15.8.2, and the same tag helpers ARE purple and bold in another project.

Here's some code (cshtml):

<form method="post">
    <div asp-validation-summary="All" class="text-danger"></div>
    <table>
        <tr>
        <td>@Html.DisplayNameFor(model => model.NoteModel.NoteName)</td>
        <td><input asp-for="NoteModel.NoteName" class="form-control" data-val-required="The NoteName field is required." data-val-maxlength-max="15" data-val="true" /></td>
        <td><span asp-validation-for="NoteModel.NoteName" class="text-danger"></span></td>
        </tr>
        <tr>
        <td>@Html.DisplayNameFor(model => model.NoteModel.TranslatedNoteName)</td>
        <td><input asp-for="NoteModel.TranslatedNoteName" class="form-control" data-val-required="The TranslatedNoteName field is required." data-val-maxlength-max="100" data-val="true" /></td>
        <td><span asp-validation-for="NoteModel.TranslatedNoteName" class="text-danger"></span></td>
        </tr>
        <tr>
        <td>@Html.DisplayNameFor(model => model.NoteModel.NoteText)</td>
        <td><textarea asp-for="NoteModel.NoteText"
                  class="form-control" data-val-required="The NoteText field is required." 
                  data-val-maxlength-max="8000" data-val="true" 
                  data-val-maxlength="The field NoteText must be a string or array type with a maximum length of '8000'."
                  rows="20" cols="100"></textarea></td>
        <td><span asp-validation-for="NoteModel.NoteText" class="text-danger"></span></td>
        </tr>
    </table>

    <div>
        Upload an image: <input type="file" name="image" accept=".jpg" />
    </div>

    <div class="form-group">
        <button type="submit" class="btn btn-default">Upload</button>
    </div>
</form>

There're data annotations in the NoteModel class, and @Html.DisplayFor renders them properly.

Any ideas? Thanks in advance.

UPDATE:

Tags are not rendered properly into HTML, all the attributes asp- stay in HTML. Apparently, I'm doing some silly mistake, which I'm not able to figure out.


Solution

  • Tag helpers are an opt-in feature. They are not available to the page by default. They are enabled by adding an @addTagHelper directive to the page, or more usually to a _ViewImports.cshtml file:

    @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    

    Check to see if the taghelpers are enabled.

    Ref: https://www.learnrazorpages.com/razor-pages/tag-helpers/