Here are some ways to solve the path that this root application operator uses ( ~ )
To call any method with embedded code on an asp.net page, this method must either be shown as an instance variable for the current object, or available as a static / general method.
A typical MVC page gives us access to quite a few of them as properties through WebViewPage . Have you ever wondered when you type @ViewData , do you get a magical connection to ViewData? This is because you are in a property set on the MVC page where you are located.
Therefore, to call these methods, we do not necessarily refer to the type that they represent, but to the instance property that provides them.
We can call the above instance methods similar to this (respectively):
href="@Url.Content("~/index.html")" href="@Server.MapPath("~/index.html")" href="@Href("~/index.html")"
We can do this to call a generic method that does not need an instance:
href="@VirtualPathUtility.ToAbsolute("~/index.html")"
AFAIK, the MVC page does not automatically instantiate anything from the System.Web.UI namespace from which ResolveUrl is inherited. If for some reason you really wanted to use this particular method, you could just update the control and use the methods that it provides, but I would recommend against it .
@Code Dim newControl As New System.Web.UI.Control Dim resolvedUrl = newControl.ResolveUrl("~/index.html") End Code href="@resolvedUrl"
To keep things said, I would recommend using @Url.Content as it is best suited for MVC paradigms
KyleMit Dec 01 '14 at 20:58
source share