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

3
  • @URL.Action should work but you need to make sure that the action and controller exist for the helper method to generate the link Commented Aug 1, 2021 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 cookiesandyou.com Commented Aug 1, 2021 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 Commented Aug 1, 2021 at 19:29

1 Answer 1

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.

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

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.