2009-01-14 44 views
0

在.NET應用程序中使用ASP.NET用戶控件(.ascx文件)來填充自己的模板需求,而不是該應用程序是網站嗎?在沒有Website項目的情況下使用ASP.NET usercontrols進行模板化?

它實際上是一個類庫,它將數據放入模板中,然後將其與模板混合,然後吐出。

我不想從頭開始寫自己的模板系統,所以我正在尋找重用ASP.NET功能來滿足我的需求。

有人告訴我,ASP.NET用戶控件呈現依賴於IIS。是否有一些黑客或詭計讓它在.NET類庫中工作?

回答

1

我不完全確定我是否正確地處理了這個問題,但如果您只是在尋找一個模板引擎,您可能需要查看NVelocity,這是Castle Project的一部分。

它允許你創建這樣的一個模板(從入門指南撕開網站上):

From: $from 
To: $to 
Subject: $subject 

Hello $customer.Name 

We're please to yada yada yada. 

然後propulate它像這樣:

Template template = velocity.GetTemplate(@"path/to/myfirsttemplate.vm"); 
VelocityContext context = new VelocityContext(); 
context.Put("from", "somewhere"); 
context.Put("to", "someone"); 
context.Put("subject", "Welcome to NVelocity"); 
context.Put("customer", new Customer("John Doe")); 

StringWriter writer = new StringWriter(); 
template.Merge(context, writer); 
Console.WriteLine(writer.GetStringBuilder().ToString()); 
相關問題