Can't get site root url in asp mvc

前端 未结 5 1215
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 21:13

I need to get site root url in razor page in javascript code:

...
var siteRootUrl = \'@Url.Content(\"~\")\';
...

But all I get from this is

5条回答
  •  爱一瞬间的悲伤
    2020-12-30 21:19

    @Url.Content() returns the root RELATIVE path, that is the path from the root of the domain.

    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.

提交回复
热议问题