Home > other >  The anchor element doesn't recognized on specify positions with tag helpers .Net core 6
The anchor element doesn't recognized on specify positions with tag helpers .Net core 6

Time:10-11

I'm working with .Net Core 6 and currently I have problems to make it works the elements with tag helpers.

<div >
<div >
    <div >
        <h2 >Category List</h2>
    </div>
    <div >
        <a asp-controller="Category" asp-action="Create" >
            <i ></i>&nbsp; Create new category
        </a>
    </div>
</div>
<br /><br />

<table  style="width: 100%;">
    <thead>
        <tr  ">
            <th scope="row">Category Name</th>
            <th scope="row">Display Order</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var category in Model)
        {
            <tr>
                <td width="50%">@category.Name</td>
                <td width="30%">@category.DisplayOrder</td>
                <td>
                    <div  role="group">
                        <a asp-controller="Category" asp-action="Edit" asp-route-id="@category.Id" >
                            <i ></i> Edit
                        </a>
                    </div>
                </td>
            </tr>
        }
    </tbody>
</table>

Here the first anchor works perfectly,

<a asp-controller="Category" asp-action="Create" >
   <i ></i>&nbsp; Create new category
</a>

But when I'm using the next one, and I run the application, the navigator does not recognize the tag and does not create automatically the sintax to add the href tag.

<a asp-controller="Category" asp-action="Edit" asp-route-id="@category.Id" >
                                <i ></i> Edit
                            </a>

CodePudding user response:

After testing, I finally found the reason.

The problem is with this line of code:

<tr  ">

It has one more ".

Remove it, the href will be displayed normally.

<tr >

enter image description here

  • Related