This project is read-only.

Url.Content( doesn't work.

Mar 3, 2011 at 6:11 PM
Edited Mar 3, 2011 at 6:12 PM


<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />    
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>



I'm sure there's an obvious cause for this, but what is the workaround?  

RazorEngine looks great for templating our customer portals, but a bunch of the built in view functions are broken.  Is there a workaround for stuff like this?  

Mar 4, 2011 at 3:17 PM

Correct. The RazorEngine is *not* the same as the MVC Razor Engine. All helpers available in MVC, such as, Html and Url, cannot be found. You would need to create your own TemplateBase which has these methods available in them. Think of RazorEngine more as a c# xml parser rather than an html parser.

Apr 13, 2011 at 4:57 AM

Do you have an example that you could post showing how to create a TemplateBase class where you could set properties like Url or Html to represent the UrlHelper/HtmlHelper properties?  It looks like you can only pass the type of the TemplateBase, not an instance... In my case, I already have access to an existing UrlHelper object and would like to just pass that rather than construct a new one.

Apr 13, 2011 at 4:43 PM

The simplest example can be found here.

The key points are:

public abstract class MyCustomTemplateBase<T> : TemplateBase<T>
public string ToUpperCase(string name)
return name.ToUpperCase();



Jun 20, 2011 at 8:12 PM

I have a similar problem. I have to pass an instance of an object to my template class (Url/Html helpers and others, eg. resolved from IoC container). It seems there's no way to do that as Razor engine does the instantiation from given type under the hood... Or am I missing something?

Jun 20, 2011 at 8:41 PM

I guess there's a way to achieve that - provide custom Activator via Razor.SetActivator method (an override allows a simple lambda to be passed, cool!), which creates instances of ITemplate objects. Within that activator you are free to set any necessary properties on the custom template base object (like Urland Html).

Jun 21, 2011 at 1:23 AM

If you are trying to template a portal, presumably a website, why are you trying to use Razor Engine instead of just creating views or page (MVC or WebPages) using Razor?

RazorEngine allows you to do templating in or outside of a Web Applicaton, but is best used for other things than web pages as you get more functionality, such as helpers, using the Razor View Engine (not Razor Engine).