Lesscss and ASP.NET MVC

大城市里の小女人 提交于 2019-12-03 12:38:15

You should specify the mime type for the less file extension in your web.config and use that in your link instead if css.

<system.webServer>
  <staticContent>
    <mimeMap fileExtension=".less" mimeType="text/css" />
  </staticContent >
</system.webServer>

Personally I thing using dotless and processing this on the server is a better way to go.

Also, not really an answer to your question, but just a side point -- with MVC4 you no longer need @Url.Content(). http://www.davidhayden.me/blog/asp.net-mvc-4-the-new-tilde-slash-feature-in-razor-2

BLeB

In my opinion, a simple way to set this up better is using nuget. You don't have to use nuget but it just makes things so easy.

  1. Install dotless using nuget.
  2. Install System.Web.Optimization.Less using nuget.
  3. Add your bundle

    bundles.Add(new LessBundle("~/Content/less")
                    .Include("~/Content/less/more.less"));
    
  4. Reference the bundle

    @Styles.Render("~/Content/less")
    
  5. Done

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!