0
我需要知道如何在沒有其他情況下使用三元運算符。在這個例子中,我需要檢查2個標準(cityId != null) && (cityId != 0)
。我不能使用正常條件。所以如果沒有發生,我想列出所有的標題。我不想展示在其他條件x.ProvinceId == 15
在linq中使用三元操作而不使用其他操作?
public JsonResult mt(int? cityId)
{
var getCities = locationRepository.Get(null).Where(x => ((cityId != null) && (cityId != 0) ? x.ProvinceId == cityId : x.ProvinceId == 15 )).Select(x=>x.Title);
return Json(new { items = getCities }, JsonRequestBehavior.AllowGet);
}
它被稱爲條件運算符 –