0

I have this error in the navbar in asp.net mvc

enter image description here

And this id my code

                <li class="nav-item  nav-link" role="presentation">

                    <a class="nav-link" @Html.ActionLink("Customers", "Index", "Customers") />

                </li>

So why this character come />

The close for the

2 Answers 2

1

You're using Html.ActionLink inside anchor tag, which is totally wrong:

<a class="nav-link" @Html.ActionLink("Customers", "Index", "Customers") />

I suggest you to use ActionLink helper alone with @class attribute instead:

@Html.ActionLink("Customers", "Index", "Customers", null, new { @class = "nav-link" })

Or use @Url.Action with anchor tag:

<a class="nav-link" href="@Url.Action("Index", "Customers")">Customers</a>
Sign up to request clarification or add additional context in comments.

Comments

0

You need to change the line:

<a class="nav-link" @Html.ActionLink("Customers", "Index", "Customers") />

to

<a class="nav-link" href="@Url.Action("Index", "Customers")">Customers</a>

or:

@Html.ActionLink("Customers", "Index", "Customers", null, new {@class = "nav-link"})

This is because @Html.ActionLink() generates the entire anchor (<a>) element whereas @Url.Action() just generates the URL for the route, you need to do one or the other.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.