[英]Does NHAML require ASP.NET MVC?
無法在NHAML項目頁面上直接找到它,所以我想知道您是否需要運行ASP.NET MVC才能使用NHaml還是可以在“常規” ASP.NET網頁上使用它?
另外,我讀到您需要攔截對Sass的請求並手動為其調用構建器?
問題在這里與答案有些重復: NHaml可以用作通用模板引擎嗎? (在MVC之外)
引用:
是的,它可以在沒有ASP.Net MVC的情況下使用。 我將其用於自己的Web服務器(但這並不意味着您必須將其用於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 = this;
// 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);
不,盡管有實現,但它不需要ASP.NET MVC。 您甚至可以在控制台應用程序中處理NHaml模板。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.