我想根据所选国家/地区绑定2个下拉列表City
和Currency
。因此,我使用了Json并通过了所选的countryId并在控制器中写入以获取相应的货币和城市值。但问题是,如何在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
}
答案 0 :(得分:1)
像这样做
return Json(new {city = City, curreny = Currency });
OR
return Json(new {City, Currency})
检查辅助方法中的参数列表,它不会占用多个数据对象,你必须将它们包装在对象下并相应地访问客户端。
如果您需要帮助,请告诉我
答案 1 :(得分:1)
使用
return Json(new { City, Currency });