Public class AbcViewModel
{
public string native{get; set;}
public string other{get; set;}
public List<AbcViewModel> abcList{get; set;}
}
既然我的視圖是強類型的這個ViewModel,我需要檢查一些條件之前顯示字段。C#列表上的條件聲明
從我的控制器操作,我通過列表
public ActionResult actionName()
{
AbcViewModel viewModel=new AbcViewModel();
viewModel=model.getAbcList();
return View(viewModel);
}
條件:如果認爲我的列表中包含n
計數。然後,如果任何索引的任何「本地元素」保持某個值,則顯示其他字段並隱藏,反之亦然。
即 像這樣的事情
@if (Model.languageList.Any(x => x.nativeLanguage.IsNotEmpty() == false)
{
@LabelFor(x=>x.other)
}
else
{
@LabelFor(x=>x.native)
}
這是不正確的語法,我認爲(IsNotEmpty不是一個有效的方法)。
告訴我這樣做的正確方法。
感謝KIM它的工作 – RollerCosta 2012-03-26 10:48:26