私は辞書を構築するC#の関数を持っています。この辞書を自分のjava-script関数に渡す必要があります。辞書をc#(サーバ)からjavascript(クライアント)に渡す方法
これは私が
私のサーバ機能に
public partial class login : System.Web.UI.Page
{
protected Dictionary<string, string> GetTradingTypeToSelect()
{
Dictionary<string, string> dict = new Dictionary<string, string>();
try {
string Types =GetString("some text);
var items = Types.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => s.Split(new[] { '=' }));
foreach (var item in items)
{
dict.Add(item[1], item[0]);
}
//this working 100%
}
catch (Exception ex)
{
}
return dict;
}
}
を試してみましたが、どのような私のクライアントです:
$(document).ready(function() {
$("#Account").keyup(function() {
var TradingTypeToSelect = '<%=GetTradingTypeToSelect();%>';
//TradingTypeToSelect is equals to string '<%=GetTradingTypeToSelect();%>'
var test = TradingTypeToSelect[0].key;
var test2 = TradingTypeToSelect[0].value;
});
});
は、私はここで何をしないのですか?
あなたはajax postメソッドを使用できます。このリンクを確認してください。 http://stackoverflow.com/questions/7776337/reading-c-sharp-dictionary-in-javascript –
@PonmaniChinnaswamyなぜ投稿しますか? OPがデータを取得する必要があり、パラメータを送信していない場合は、 – Mateusz