I need to get site root url in razor page in javascript code:
... var siteRootUrl = \'@Url.Content(\"~\")\'; ...
But all I get from this is
@Url.Content() returns the root RELATIVE path, that is the path from the root of the domain.
@Url.Content()
So if your site was at www.foo.com/site then Url.Content() returns /site
Ishmael's response is correct. You will need to parse a full url.