繁体   English   中英

NHAML是否需要ASP.NET MVC?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM