Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:54:54+00:00 2026-06-10T10:54:54+00:00

I have MVC 3 application and I have dictionary of type Dictionary<String,int> in c#.

  • 0

I have MVC 3 application and I have dictionary of type Dictionary<String,int> in c#. I have pass this dictionary using ViewBag to the Layout view from the Index action. Layout view consist of the jquery code. Here, I want to built array as follows in jquery.

var s1 = [['06/15/2009 16:00:00', 112000], ['06/16/2009 16:00:00', 122000], ['06/17/2009 16:00:00', 104000], ['06/18/2009 16:00:00', 99000], ['06/19/2009 16:00:00', 121000],
            ['06/20/2009 16:00:00', 148000], ['06/21/2009 16:00:00', 114000], ['06/22/2009 16:00:00', 133000], ['06/22/2009 16:00:00', 161000], ['06/23/2009 16:00:00', 173000]];

How Can I built above jquery array looping through dictionary which passed using viewbag.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:54:56+00:00Added an answer on June 10, 2026 at 10:54 am

    How Can I built above jquery array looping through dictionary which passed using viewbag.

    First things first there’s no such notion as jquery array. It’s called javascript array. Second why do you wanna loop at all?

    Use a JSON serializer to do the job for you:

    @model Dictionary<string, int>
    <script type="text/javascript">
        var s1 = @Html.Raw(
            Json.Encode(
                Model.Select(x => new object[] { x.Key, x.Value })
            )
        );
    </script>
    

    Oh sorry, I forgot that you are using ViewBag and not view models (which is what you should be using). In this case you will need to cast whatever you have stuffed into this ViewBag to the corresponding type before being able to do something useful with it (such as a LINQ query for example):

    <script type="text/javascript">
        var s1 = @Html.Raw(
            Json.Encode(
                ((Dictionary<string, int>)ViewBag.SomeDict).Select(x => new object[] { x.Key, x.Value })
            )
        );
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an mvc application that I allow businesses to log in using https://storea.mydomain.com
I have an MVC application created from the Internet template to use forms authentication,
I have an MVC application that is using MEF for the controllers, all working
I have an MVC application view that is generating quite a large HTML table
I am working in an ASP.NET MVC Application. I have a view model as
I am creating a modular ASP.NET MVC application using areas. In short, I have
I am using glimpse.mvc in an ASP.NET MVC 3 application. I have a ReportController
I have ASP.NET MVC controller named dictionary with method ControlsLangJsFile. Method returns view of
I am developing an application using MVC Preview 5. I have used typed views.
I have mvc 3 application in which i'm having one input form on Index.cshtml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.