0

I want to pass array value for creating graph of jplot function. In Layout cshtml it consist of jquery function for creating the graph and it have an array in the form of:

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]];

I have passed dictionary value to this layout using viewbag and use following code to loop through dictionary.

  @foreach (KeyValuePair<String, int> kvp in ViewBag.dateRange)
                    {  
                        @kvp.Key
                       @kvp.Value          
                    }

How can I built above array for jquery function using razor engine. Dictionary have string and int where string is date value and int is total number value.

1
  • Why do you want to use ['06/15/2009 16:00:00', 112000] as array, but not as object? Commented Aug 25, 2012 at 6:52

1 Answer 1

1

try this

@{
    var dic = ViewBag.dateRange as Dictionary<String,int>;
}

var s1 = [@(String.Join(",", dic.Select(d => String.Format("['{0}',{1}]", d.Key, d.Value)));)];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.