Looking to integrate JavaScript into my project... I have data stored in a database...... Retrieving it using LinQ as shown below
public List<SelectListItem> getTokens()
{
var tokens = from T in db.tokens select T;
List<SelectListItem> items = new List<SelectListItem>();
foreach (var t in tokens)
{
items.Add(new SelectListItem { Value = t.id.ToString(), Text = t.tname });
}
return items.ToList<SelectListItem>;
}
Alternatively
public string getTokens()
{
var tokens = from T in db.tokens select T;
string s = "[";
foreach (var t in tokens)
{
s += "{ id:" + t.id.ToString() + ", name: " + t.tname + "},";
}
s += "]";
return s;
}
I am looking for a way to pass this string/list to my JS function like so...
$(document).ready(function() {
$("#demo-theme").tokenInput([
{ id: 7, name: "Ruby" },
{ id: 11, name: "Python" },
{ id: 13, name: "JavaScript" },
{ id: 17, name: "ActionScript" },
{ id: 19, name: "Scheme" },
{ id: 23, name: "Lisp" },
{ id: 29, name: "C#" },
{ id: 31, name: "Fortran" },
{ id: 37, name: "Visual Basic" },
{ id: 41, name: "C" },
{ id: 43, name: "C++" },
{ id: 47, name: "Java" }],
{theme: "ab"
});
});
I am seeking a solution to replace the initial list of items with my string/list... Or any other method to achieve this....