简体   繁体   中英

Dropping Json object on html page in asp.net mvc2

im 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

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

Now you can use the obj global variable:

alert(obj.foo);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM