Search code examples
c#jqueryasp.net-mvcidictionary

ASP.NET MVC: How to pass Dictionary<string, string> from controller to jquery for use?


As I am quite green for ASP.NET MVC so maybe my question is very simple for many experienced users.

I am now implementing a web-based platform and I am trying to pass some data in Dictionary from Controller to View using ViewBag.

However, I am not able to use those ViewBag in jQuery, when I "alert" them, they become a series of [Object, Object].

So I would like to ask how I can retrieve those data in jQuery?

Thanks.


Solution

  • You can serialize a .NET dictionary to Json. The Json.NET library has first class support for this