The reporting engine MailMerge is used to merge templates with data. In combination with the HTML5 based MVC editor Web.TextControl, the created template can be merged in the MVC controller and loaded back into the view.

The following HttpPost method Merge accepts the model DocumentViewModel which contains the template encoded as a Base64 string. The data source is loaded into a new DataSet object. Finally, the template is loaded into a new instance of the MailMerge class and merged with the loaded DataSet. The created document is returned to the view.

public string Merge(DocumentViewModel model)
// convert the template to a byte array
byte[] document =
// load the the data source
DataSet ds = new DataSet();
byte[] sDocument;
// create a new ServerTextControl and MailMerge component
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
MailMerge mm = new MailMerge();
mm.TextComponent = tx;
// load the template and merge
mm.Merge(ds.Tables[0], true);
// save the document
mm.SaveDocumentToMemory(out sDocument,
TXTextControl.BinaryStreamType.InternalUnicodeFormat, null);
// encode and return the merged document
return Convert.ToBase64String(sDocument);
view raw HomeController.cs hosted with ❤ by GitHub

The contoller method is called from the Javascript function Merge. The current document is saved into a Base64 encoded string and is being sent using AJAX to the controller method Merge.

When the controller method returns successfully, the merged document is loaded into the editor.

function Merge() {
// save the document
function (e) {
var serviceURL = "/Home/Merge";
// call the controller
type: "POST",
url: serviceURL,
contentType: 'application/json',
data: JSON.stringify({
success: successFunc,
error: errorFunc
// the controller sends back the merged document
// that is loaded into the editor
function successFunc(data, status) {
TXTextControl.streamType.InternalUnicodeFormat, data);
alert("Document has been merged successfully.");
function errorFunc() {
view raw tx.js hosted with ❤ by GitHub

Download the sample from GitHub and test it on your own.