2013-03-01 77 views
1

我想根據所選國家/地區綁定2個下拉菜單CityCurrency。所以我使用了Json並通過了選定的countryId,並在控制器中寫下相應的貨幣和城市值。但問題是,我如何在json中傳遞2個值作爲返回類型?如何從json傳遞2個對象作爲返回

下面是代碼:

[HttpPost] 
    public ActionResult BindCityAndCurrency(int CountryID) 
    { 
     var q = from r in db.Cities where r.CountryID == CountryID orderby r.CityID, r.CityName select r; 

     var City = q.ToList().Select(c => new { Text = c.CityName, Value = c.CityID }); 
     var Currency = from items in db.Currencies where items.CountryID == CountryID orderby items.CurrencyName, items.CurrencyName select items; 
     return Json(City,Currency);//here is the error showing Invalid Arguments I 
    } 

回答

1

使它像這樣

return Json(new {city = City, curreny = Currency }); 

OR

return Json(new {City, Currency}) 

檢查輔助方法的參數列表,它不服用多種數據對象,你必須將它們包裝在對象上,並相應地在客戶端訪問。

請讓我知道如果你需要任何幫助

+0

感謝alot.Its工作。 – user2090114 2013-03-01 09:56:32

+0

+1給你:),歡迎 – 2013-03-01 09:57:06

1

使用

return Json(new { City, Currency });