views:

24

answers:

1

Hi, i m using asp.net mvc2 and i want to drop some json objects from my controller similar to validation metadata. when we call Html.ClientValidation() before our form it drops some javascript on the page like

<javascript type="text/javascript">
    <!--CDATA[validation metadata]-->
</javascript>

i want to have some json objects dropped in my page that i can use through jquery

thanks in advance

+1  A: 
<script type="text/javascript">
    var obj = <%= new JavaScriptSerializer().Serialize(new { foo = "bar" }) %>;
</script>

Now you can use the obj global variable:

alert(obj.foo);
Darin Dimitrov
thanks darin. i will try it tomorrow
Muhammad Adeel Zahid