0

Based on Calling ASP.NET MVC Action Methods from JavaScript I've attempted to update a cookie message using ASP.NET Core by :

  1. replacing href by window.location.href and

  2. specifying ActionName + ControllerName.

  3. I've also tried window.location.href = '@Url.Action("Action", "Controller")

[Problem] : When clicking on the link, 1-3 redirect to https://www.cookiesandyou.com/, instead of https://localhost/ControllerName/ActionName . Please see below a sample code:

    window.cookieconsent.initialise({
    ....
},
"showLink": true,
"content": {
    "message": "test ",
    "window.location.href": "Dat?Home",
    "allow": "Allow"
}

});

Any idea would highly be appreciated.

N.B: Using ASP.NET, this tasks was trivial since href was simply pointing to /Dat.

Best

dark.vador
  • 619
  • 1
  • 6
  • 25
  • @URL.Action should work but you need to make sure that the action and controller exist for the helper method to generate the link – Canolyb1 Aug 01 '21 at 19:15
  • @Canolyb1: they do exist, as I've tested ```href: Home/Dat```. Problem was when clicking 2x on the same link, URL was point to ```Home\Home\Dat```, hence an exception. So I have to resort to solution posted which was strangely pointing https://www.cookiesandyou.com/ – dark.vador Aug 01 '21 at 19:22
  • to be a bit more accurate: href": "Home/Dat" points to the right url. However, ```window.location.href: Home/Dat``` points to cookiesandyou.com for unknown reasons. Unfortunately href = '@Url.Action("Action", "Controller") does not work and wonder whether a solution involving href could exist – dark.vador Aug 01 '21 at 19:29

1 Answers1

0

Eventually, using:

"href: '/Home/Dat',"

solves my issues : No automatic pointing to cookiesandyou.com, and clicking n times to the link did not point to Home\...\Dat, thus yielding errors owing to the insertion of /.

Best.

dark.vador
  • 619
  • 1
  • 6
  • 25