Search code examples
asp.net-mvcasp.net-corerazor-pages

@Html.ActionLink, @Url.Action do not work in asp.net core razor view


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?


Solution

  • 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.