Try our conversational search powered by Generative AI!

How to get system.css in MVC Razor


Hi guys,

I want to get system.css of EpiServer. I searched some topic and I found this

Html.CssLink(EPiServer.Web.PageExtensions.ThemeUtility.GetCssThemeUrl(Page, "system.css"))

But this code cannot work on MVC with razor engine and here is its error

'System.Web.Mvc.HtmlHelper' has no applicable method named 'CssLink' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

Could you help me how to get system.css in MVC Razor?

Thank in advance,

Nov 16, 2015 7:41


Can anyone help to solve this?


Nov 19, 2015 4:44

It seems lacking a @using to the namespace contains the extensions: EPiServer.Framework.Web.Mvc.Html

Edited, Nov 19, 2015 7:53
<p>Hi GP,</p> <p></p> <p>I've already using EPiServer.Framework.Web.Mvc.Html in my code. The problem is method GetCssThemeUrl required object Page, but Page variable I can only get from WebPageBase which have data type is dynamic. I tried to parse it to Page but I didn't know how.</p> <pre class="brush:csharp;auto-links:false;toolbar:false" contenteditable="false">public class ThemeUtility { ... public static string GetImageThemeUrl(Page page, string imagePath); ... }</pre> <pre class="brush:html;auto-links:false;toolbar:false" contenteditable="false">public abstract class WebPageBase : WebPageRenderingBase { ... public override dynamic Page { get; } ... }</pre> <p><img src="" width="890" alt="" height="349" /><br /><br /></p>
Nov 19, 2015 8:14


Did you tried to use: @Html.ShellCssLink("system.css")

or calling this as static method: @CssExtensions.ShellCssLink(Html, "system.css") ?

Nov 19, 2015 10:01


Thank for reply, your code have no error but it generated path"/EPiServer/Shell/" which is not found. Existed system.css I want to get is "/App_Themes/Default/Styles/system.css"

Nov 19, 2015 10:20

I just used plain HTML tags for system.css (and ToolButton.css). Since they are under App_Themes they are not dependent on the version number, so should (hopefully) be OK after upgrading to new versions.

So I have

<link href="/App_Themes/Default/Styles/system.css" rel="stylesheet" />
<link href="/App_Themes/Default/Styles/ToolButton.css" rel="stylesheet" />

Works for me in CMS

Happy to hear if there's a better solution for this.
Dec 09, 2015 14:56
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.