2

I am trying to use the @Html.ActionLink and @Url.Action in my razor pages.

for this I have the following code in my view

<div Id="SetLanguageUrl" value="@Url.Action("SetLanguage", "Language")"></div>
@Html.ActionLink("Test", "SetLanguage", "Language")

I do not get an error on this, but both do not resolve the url as can be seen in the browser development tools screenshot.

browser developer tools screenshot

Anybody know what I could be missing?

1 Answer 1

2

Ok, this has been very frustrating but here is the solution.

In Startup.cs - configure I had the following:

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });

When I change this to:

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });

It seems to work.

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

3 Comments

You can change it to endpoints.MapDefaultControllerRoute();, if you dont need to modify the default route.
Thank you, that does indeed work and is more concise.
Mark your "answer" as Answer, will help others if they have the same Question.

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.