I have this code , and i want to store values of parameters left, top in static dictionary. and after storing this values i want to access them in Jquery.Thanks For your Help.
my code
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication1.MoveShape
{
public class MoveShapeHub : Hub
{
public void calculate(string left, string top)
{
Clients.Others.updateshape(left, top);
}
}
}
jQuery operates client-side, so you can't talk to it directly. You have two options, then:
Fortunately, the latter is fairly trivial for most common types - here using Json.NET:
var data = new Dictionary<string, object>
{
{"foo", 123},
{"bar", "abc"},
{"blap", true}
};
var json = JsonConvert.SerializeObject(data);
which gives us the JSON:
{"foo":123,"bar":"abc","blap":true}
If you assign that into a variable in the <script>
, then values can be referenced either as obj.bar
or as obj['bar']
. However: keep in mind that all values will be serialized if you do this - you may want to be more restrictive in terms of tracking which the client actually cares about (or should be allowed to know about).
Important point, though: if your "static dictionary" is actually a static
dictionary, then please consider very carefully the impact of multiple users. static
is a really good way to write a web-site that only scales to a single user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With