0
我已閱讀this在Asp.Net MVC5中使用Less
的教程。less.modifyVars在Asp.Net中無效MVC
要將LESS集成到ASP.NET MVC中,我下載並安裝了dotless NuGet包。
,然後添加該軟件包:
var lessBundle = new Bundle("~/Less").Include("~/Content/Less/*.less");
lessBundle.Transforms.Add(new LessTransform());
lessBundle.Transforms.Add(new CssMinify());
bundles.Add(lessBundle);
這裏是LessTransform
:
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
response.Content = dotless.Core.Less.Parse(response.Content);
response.ContentType = "text/css";
}
}
到目前爲止好。一切都按預期工作。
這裏是我的.less
文件中的一部分:
@CustomMessageBackgroundColor: #65B6A7;
div.custom-dialog {
...
background: @CustomMessageBackgroundColor;
}
現在,我想這個變量的值從.js
文件動態改變:
less.modifyVars({ '@CustomMessageBackgroundColor': 'blue' });
less.refreshStyles();
但是,這是行不通的。 我已閱讀所有SO問題,據我所知,這必須工作。
謝謝。
感謝您的回答。所以我必須使用'Less.js'而不是'dotless'?說實話,我想基於用戶選擇chiage ui主題。所以,我決定使用Less。 –
*必須*是一個強詞。 Dotless通過查詢字符串參數支持動態變量,但是捆綁變得有點問題。這一切都取決於你真正需要完成的,但可能更少.js是你最好的選擇。 :) – Rytmis
我做了另一個調查。並發現Web Essentials已經支持.less文件。但是,我不知道如何從JavaScript中獲取變量?你有什麼練習嗎? –