0
我需要從json結果中讀取每個值,並向控制器動作請求。 這是我的客戶端。Mvc:從json中使用JavaScript數組獲取值到mvc控制器
$.ajax({
type: "POST",
url: "List",
data: { firstArray: arrayCountries, secondArray: arrayLang },
success: function (result) {
//here i need each value from json, but it's not working for me
},
dataType: "json",
traditional: true
});
好吧,現在我使用這種方式,因爲我需要發送2個javascript數組,並且在找到很多這種方式後對我很有用。
而這是我的服務器端。根據How can I post an array of string to ASP.NET MVC Controller without a form?我創建了這個。
public ActionResult List(List<String> firstArray, List<String> secondArray)
{
//But here i need a list of sections, so i call a method for that
var sections = SomeClass.getSections(fistArray, secondArray);
//And return the json with the collection
return Json(sections, JsonRequestBehavior.AllowGet);
}
現在,這是我的getSections方法
public static IEnumerable getSections(List<String> firstArray, List<String>secondArray)
{
entities db = new entities();
var result = from values in db.Sections
where ...
select new SectionsModel{ // do something };
return result.OrderBy(p => p.Description);
}
現在即時得到的客戶端以及JSON,但我不知道如何進入電影吧,我怎麼可以從它那裏得到的每個值? ... 提前致謝。
即時得到螢火蟲JSON.parse做什麼:意外的字符......是什麼問題json格式? – Steve 2013-04-23 23:00:26
通話結束時結果的值是多少? – Kenneth 2013-04-23 23:01:30
它就像[對象對象],[對象對象] – Steve 2013-04-23 23:06:35