ASP.NET MVC - @Import LESS variables returned from controller

0 views
Skip to first unread message

Rod Early

unread,
Apr 6, 2017, 10:43:51 PM4/6/17
to LESS - Leaner CSS

I am attempting to return LESS variables in the response from an ASP.NET MVC controller method -- which are @imported into the body of a LESS file. The purpose is to allow users to customize the appearance of of a multi-tenant web application.

This almost works.

public class StyleController : Controller
{
  // GET: Style
public string Index()
{
     var ResponseLess = new StringBuilder();
     ResponseLess.AppendLine("@color1: red!important;");
     ResponseLess.AppendLine("@color2: green!important;");           
     Response.ContentType = "text/css";

     return ResponseLess.ToString();
}
...
};

The sample.less file that imports the response of the above controller...

@color1: yellow!important;
@color2: lime!important;

h1 {
    color: @color1;
}

h2 {
    color: @color2;
}

@import (less) url('http://localhost:50274/Style/Index');

Also in BundleConfig.cs, I include the following to include the LESS files...

bundles.Add(new StyleBundle("~/Content/less").Include("~/Content/*.less"));

I had to define the variables @color1 and @color2, otherwise I get an error that those variables do not exist.

I can see in the Chrome Debugger Network monitor that the StyleController Index method returns the response I expect -- the LESS variables. However, LESS apparently is not recognizing those variables; most likely it doesn't consider the response to be valid LESS.

What am I missing or misunderstanding?

Thanks, Rod Early


(Also posted on StackOverFlow
Reply all
Reply to author
Forward
0 new messages