0

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
bill
  • 854
  • 3
  • 17
  • 41
  • 1
    Data passed from the controller to the view should be kept on the ViewModel it pains me to see why people use the ViewData store. – James Dev Apr 01 '16 at 08:42

1 Answers1

1

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

<script>
     var data = @Html.Raw(Json.Encode(ViewData["JsonRegionList"]))
</script>
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69