MS Word provides a quick insert table drop-down to insert tables into the document. This sample shows how to replace the insert table button with such a table insert drop-down.

MVC: Replace the ribbon table menu with a quick insert table drop-down

The replacement and the new drop down button is done using Javascript and can be found in the GitHub repository. In order to insert the specific table, a controller method is called using Javascript:

function getTableFromController(cols, rows) {
var serviceURL = "/Home/GetTableFromController";
$.ajax({
type: "POST",
url: serviceURL,
contentType: 'application/json',
data: JSON.stringify({
Columns: cols,
Rows: rows
}),
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
TXTextControl.loadSelection(TXTextControl.streamType.InternalUnicodeFormat, data);
}
function errorFunc() {
alert('Error');
}
}
view raw tx.js hosted with ❤ by GitHub

The controller method creates a new ServerTextControl instance to insert the specified table. The document is returned to the client and inserted at the current input position using the Javascript method loadSelection.

[HttpPost]
public string GetTableFromController(Table model)
{
byte[] data;
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
{
tx.Create();
tx.Tables.Add(model.Rows, model.Columns);
tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
}
return Convert.ToBase64String(data);
}
view raw HomeController.cs hosted with ❤ by GitHub

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