I need to get site root url in razor page in javascript code:
...
var siteRootUrl = \'@Url.Content(\"~\")\';
...
But all I get from this is
The @Url.Content is returning the relative URL which is correct. The following code gives you various option in getting a URL realtive via code, absolute Url via code, absolute via javascript:
Site 'Relative Url = '@Url.Content("~")'
Site 'Absolute Url = '@System.Web.HttpContext.Current.Request.Url.AbsoluteUri'
You will get something like:
Site 'Relative Url = '/' Site 'Absolute Url = 'http://localhost:14763/'
and also the JS alert showing the href/absolute Url