The ASP.NET Core NuGet packages for DS Server provide all required components to create and merge templates with JSON data. This sample shows how to merge a template server-side with JSON data that has been created with the DocumentEditor.

The following model is used as the merge data model that is loaded into the editor to provide the proper merge field names and also for merging the final document server-side:

Loading...

In the HomeController, JSON data is loaded and passed as the view model to the actual view that contains the editor:

Loading...

The actual view contains the editor and a button that calls a JavaScript function to merge the document. The JsonData property is used to load the model we created in the controller:

Loading...

The JavaScript function mergeDocument saves the document using the saveDocument TX Text Control DS Server
JavaScript API
TXTextControl Object
saveDocument Method
Saves the current document in a certain format and sends the result back asynchronously by calling a given callback function.
method in the internal TX Text Control format in order to send it to the controller HTTP POST endpoint Merge:

Loading...

In the controller method Merge, the document is being sent with JSON data to the DS Server Web API using the Merge TX Text Control DS Server
DocumentServices.DocumentProcessing Namespace
DocumentProcessing Class
Merge Method
Merges a given template document with merge data.
method of DocumentProcessing.

Loading...

After the sample is started, find the merge fields in the Reporting tab. Insert some text, fields or repeating merge blocks:

Merging documents

After clicking the button Merge Template, the merged document is loaded back into the editor:

Merging documents

Try this on your own, create a trial token and download the sample from our GitHub account.