Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent to Page.ResolveUrl in ASP.NET MVC?

Tags:

asp.net-mvc

What is the equivalent to Page.ResolveUrl in ASP.NET MVC available in the Controller?

like image 290
Mark Redman Avatar asked Mar 16 '10 08:03

Mark Redman


People also ask

What is ResolveUrl in asp net?

ASP.NET's Control class provides the handy ResolveUrl method that lets you easily use and parse relative URLs. ResolveUrl fixes up urls that start with ~ and puts the applications relative root path in its place.

How do I change the default URL in MVC?

You can set up a default route: routes. MapRoute( "Default", // Route name "", // URL with parameters new { controller = "Home", action = "Index"} // Parameter defaults ); Just change the Controller/Action names to your desired default.


2 Answers

It is Url.Content:

ASPX:

<link rel="stylesheet" href="<%= Url.Content("~/Content/style.css") %>" type="text/css" /> 

Razor:

<link rel="stylesheet" href="@Url.Content("~/Content/style.css")" type="text/css" /> 
like image 73
Atanas Korchev Avatar answered Sep 24 '22 01:09

Atanas Korchev


This should do what you're looking for...

 System.Web.VirtualPathUtility.ToAbsolute("~/") 
like image 26
Carlo Avatar answered Sep 24 '22 01:09

Carlo