【问题标题】:Does NHAML require ASP.NET MVC?NHAML 是否需要 ASP.NET MVC?
【发布时间】:2010-11-24 08:42:05
【问题描述】:

无法直接在 NHAML 项目页面上找到它,所以我想知道您是否需要运行 ASP.NET MVC 才能使用 NHaml,或者我是否可以在“普通”ASP.NET 网页上使用它?

另外,我听说您需要拦截对 Sass 的请求并为其手动调用构建器?

【问题讨论】:

    标签: nhaml


    【解决方案1】:

    问题与这里的答案有些重复:Can NHaml be used as a general purpose template engine? (outside of MVC)

    引用:

    是的,它可以在没有 ASP.Net 的情况下使用 MVC。我将它用于我自己的网络服务器 (但这并不意味着你有 将其与 Web 服务器一起使用)。

    在这里查看我是如何使用它的: http://webserver.codeplex.com/SourceControl/changeset/view/50874#671672

    简而言之,您所做的就是 这个:

    TemplateEngine _templateEngine = new TemplateEngine();
    
    // Add a type used in the template. Needed to that nhaml can
    

    编译模板时找到 _templateEngine.Options.AddReferences(typeof (TypeInYourAssembly));

    // base class for all templates
    _templateEngine.Options.TemplateBaseType
    

    = typeof (BaseClassForTemplates);

    //class providing content to the engine, should implement
    

    ITemplateContentProvider _templateEngine.Options.TemplateContentProvider = 这个;

    // compile the template, 
    CompiledTemplate template = _templateEngine.Compile(new List<string> {layoutName, viewPath},
                                                                    typeof (TemplateImplementation));
    
    //create a instance
    var instance = (NHamlView)template.CreateInstance();
    
    // provide the view data used by the template
    instance.ViewData = viewData;
    
    // render it into a text writer
    instance.Render(writer);
    

    【讨论】:

      【解决方案2】:

      不,它不需要 ASP.NET MVC,尽管它有一个实现。如果愿意,您甚至可以在控制台应用程序中处理 NHaml 模板。

      【讨论】:

      • 我现在正在运行 MVC 2,但是当按照指南安装 NHaml 时,我似乎无法在任何地方找到 Nhaml 的 ControllerBuilder,所以我目前正在弄清楚如何获得在 ASp.NET MVC 2 上启用 Nhaml
      猜你喜欢
      • 2010-10-22
      • 1970-01-01
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多