Wednesday, January 8, 2014

How to solve "Collection was modified; enumeration operation may not execute."?

For IEnumerable collection, need to use ToList first, so you can get same list during the iteration.
                foreach (var qs in one.QuestionSets.ToList())

How to convert a string to json array in Javascript?

By JQuery:
var initQuestions = '[{ "Title": "1112", "QuestionType": { "ID": 2, "Value": "1", "Text": "Text", "Selected": true}}]';
var json = $.parseJSON( initQuestions );


How to solve "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property"?

 The default value for JavaScriptSerializer is 102400. Need to change before using:
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = int.MaxValue;