0

I'm new to ASP.net core and I was trying to write a redirect action using @Html.ActionLink

Here is my code :

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="text-center">
    <h2>Main Navigation</h2>
    <ul>
    <li>@Html.ActionLink("PRIVACY PAGE", "Privacy", "Privacy")</li>
    </ul>
</div>

This action link is supposed to redirect to the PrivacyPage, but instead, the values that I pass are being sent as a parameter to the URL

https://localhost:7020/?action=Privacy&controller=Privacy

s

The expected result is

https://localhost:7020/Privacy

enter image description here

Not sure what I'm missing. Will this ActionLink work only for the MVC projects?

Thank You !!

2 Answers 2

0

If i understand you correctly, I think you put wrong controller name.

@Html.ActionLink("link text", "actionname", "controllername")

Instead of @Html.ActionLink("PRIVACY PAGE", "Privacy", "Privacy") it will be @Html.ActionLink("PRIVACY PAGE", "Privacy", "Home")

Sign up to request clarification or add additional context in comments.

Comments

0

You can use asp-page attribute with Razor Pages.

<a asp-page="/Privacy">Privacy</a>

if your Privacy page in another folder like /Pages/Home/Privacy

<a asp-page="/Home/Privacy">Privacy</a>

For more documentation https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/anchor-tag-helper?view=aspnetcore-6.0

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.