我认为如果我可以使用新的MVC Razor View引擎作为邮件合并技术会很有趣.它仍然可以是MVC网站的一部分,而不必是独立的控制台应用程序.
例:
string myTemplate = "Hello @Name, How are you today?";
ViewModel.Name = "Billy Boy";
string output = RazorViewEngineRender( myTemplate, ViewModel );
Run Code Online (Sandbox Code Playgroud)
那么 string output = "Hello Billy Boy, How are you today?"
主要的是我希望模板是从字符串而不是视图或部分视图驱动的.
有谁知道这是否可能?
更新:
Ben和Matt在codeplex上做了一个项目:http: //razorengine.codeplex.com/
我是Knockout的新手,我正在寻找格式化输出的方法.我看到一个类似这样的例子但当然我的尝试不起作用.
这是jsfiddle的链接:http://jsfiddle.net/cezmp/
<div id="VMDiv">
<table>
<thead>
<tr>
<th>Raw</th>
<th>Formatted</th>
</tr>
</thead>
<tbody>
<tr>
<td data-bind="text : SomeData "> </td>
<td data-bind="text : formatPercent(SomeData())"> </td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
function formatPercent(value) {
return value.toFixed(2) + "%";
}
function vm() {
var self = this;
self.SomeData = ko.observable(62.1795972898);
}
ko.applyBindings(new vm(), document.getElementById("VMDiv"));
</script>
Run Code Online (Sandbox Code Playgroud)