I am looking for an automated way to create a simple C # wrapper for an existing JavaScript library. I want to create a JavaScript string using the C # class on the server, and then send the JavaScript to the client.
Example: Im creating diagrams using the KendoUI JavaScript library. I am creating JavaScript to display the server side of charts, because one page can display infinitely many charts based on how the user selects the chart setting.
The server-side JavaScript string looks like this (significantly simplified, for example):
function createChart() {
$("#chart").kendoChart({
title: {
text: "Chart Title",
},
series: [{
field: "Cost"
}],
categoryAxis: {
field: "StartDate",
}
});
}
Right now, my C # code is simply creating a string to create a JavaScript string (greatly simplified, for example):
private string CreateChartJS(string ChartTitle, string SeriesField, string CategoryField)
{
return "function createChart() { $(\"#chart\").kendoChart({ title: { text: \""+ChartTitle+"\", }, series: [{ field: \""+SeriesField+"\" }], categoryAxis: { field: \""+CategoryField+"\", } }); } ";
}
/, # JavaScript, . , Telerik ASP.NET, , , , KendoUI .
Chrome - Chrome KendoUI :

, , # , ( , , "" ).
, # (, ):
public class KendoChartWrapper
{
public class options
{
public bool autoBind { get; set; }
public class axisDefaults { }
public class categoryAxies { }
public class chartArea { }
public class dataSource { }
public class legend { }
public string name { get; set; }
public class navigator { }
public class plotArea { }
public string prefix { get; set; }
public string renderAs { get; set; }
}
}
JavaScript, # . , , #, javascript (: jQuery, jQuery UI ..).
, , , , . , - .