代码之家  ›  专栏  ›  技术社区  ›  codingbunny

nhaml是否需要ASP.NET MVC?

  •  0
  • codingbunny  · 技术社区  · 15 年前

    在nhaml项目页面上找不到这个,所以我想知道您是否需要运行ASP.NET MVC才能使用nhaml,或者我是否可以在“普通”的ASP.NET页面上使用它?

    另外,我已经读到您需要截获对SAS的请求,并为此手动调用生成器?

    2 回复  |  直到 15 年前
        1
  •  0
  •   Darin Dimitrov    15 年前

        2
  •  1
  •   Community Mohan Dere    9 年前

    Can NHaml be used as a general purpose template engine? (outside of MVC)

    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(类型为 (在您的程序集中键入));

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

    =类型(基本类模板);

    //class providing content to the engine, should implement
    

    项目面板内容提供程序 _ 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);
    
    推荐文章