开发者

How to pass Json serialized object to javascript (ASP.NET C#)

开发者 https://www.devze.com 2023-01-04 10:56 出处:网络
i have a method that returns a list of serialized objects in my page code behind private string Get() {

i have a method that returns a list of serialized objects in my page code behind

private string Get()
{
    JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer();
    string jsonString = SerializeToJas开发者_JAVA技巧on(UnavailabilityBusiness.Get(new DateTime()));
    return  jsonString ;    
}

i would like to pass this serialized objects to javascript

function getJson()
{
     ??????
}

How do I do it?


You could write them out as a script, typically leveraging ClientScript.

You would want to take care to register the script so that it renders before the consuming script.


Looks like this guy wrote a utility class to do what you're trying to do (Code Project Link).

I have't really looked at it but you can get his source and have a look.

Good luck,

Patrick.

0

精彩评论

暂无评论...
验证码 换一张
取 消