how to render the relative path with tilde into ../../ of relative path in jquery/javascript?

前端 未结 4 494
离开以前
离开以前 2021-02-06 16:50

Well, i understand my title is a bit confusing. I will state it clearly below with the example.



        
4条回答
  •  攒了一身酷
    2021-02-06 17:43

    Have a look at the VirtualPathUtility Class and this information from msdn about ASP.NET project paths.

    The VirtualPathUtility.ToAppRelative method is probably what you're looking for.

    VirtualPathUtility.ToAppRelative

    If the virtual path for the application is "myapp" and the virtual path "/myApp/sub/default.asp" is passed into the ToAppRelative method, the resulting application-relative path is "~/sub/default.aspx".

    It explains and gives examples on how to convert between different path formats.

    I also think you should to output the correct path at server level instead of reverse engineering in javascript in the browser. It may cause issues if you rearrange your project and asp changes it.

提交回复
热议问题