The most typical application for the Web.TextControl is the creation of templates for the Text Control Reporting engine DocumentServer.MailMerge. The ribbon tab Reports is designed to insert merge fields and merge blocks compatible to the reporting classes of TX Text Control.
The drop-down buttons Select Master Table, Merge Field and Merge Block are pre-filled with items of a specific Database Excerpt XML file or a DataSet that can be loaded programmatically.
Typically, the template is merged server-side with a business object created from a class model. In this case, it makes sense to pre-fill the drop-down lists from a view model as well. The following simple model is used in this sample:
[Serializable] | |
public class address | |
{ | |
public string Name { get; set; } | |
public string Street { get; set; } | |
} |
Note the Serializable attribute in the class model. In the controller, the model object is created and typically filled with data from a database. After that, the object is serialized and stored in the ViewBag:
public ActionResult Index() | |
{ | |
// create a new instance of the model | |
// fill the model from your data source here | |
address newAddress = new address() | |
{ | |
Name = "Peter Jackson", | |
Street = "2332 Paul Jackson Dr" | |
}; | |
// create a new XML document | |
XmlDocument xml = SerializeToXmlDocument(newAddress); | |
// fill the ViewBag and return the view | |
ViewBag.xmlDataSource = xml; | |
return View(); | |
} |
In the view, the LoadXMLDatabase method loads the stored XML document from the ViewBag:
@Html.TXTextControl().TextControl(settings => | |
{ | |
settings.Dock = DockStyle.Window; | |
}).LoadXMLDatabase( | |
(XmlDocument)ViewBag.xmlDataSource).Render() |
The drop-down lists are now pre-populated with the available merge fields and merge blocks:

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