bill
bill

Reputation: 864

How to access jsonstring in passed using viewdata in the view using jquery in c#, mvc

I send json string to the view using viewdata in my mvc , c# project. this is in my controller

string getregionsforSearch = csv2json.returnJsonstringFull(getregionsPath);

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            ViewData["JsonRegionList"] = serializer.Serialize(getregionsforSearch);

now I want to retrieve it in my view inside

<script></script>

and query it.how can I do that.

Upvotes: 0

Views: 776

Answers (1)

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18873

Use Json.Encode() and @Html.Raw() as shown :-

<script>
     var data = @Html.Raw(Json.Encode(ViewData["JsonRegionList"]))
</script>

Upvotes: 1

Related Questions