Public class AbcViewModel
{
public string native{get; set;}
public string other{get; set;}
public List<AbcViewModel> abcList{get; set;}
}
Now that my View is strongly typed to this ViewModel, I need to check some condition before displaying fields.
From my Controller Action I am passing the list
public ActionResult actionName()
{
AbcViewModel viewModel=new AbcViewModel();
viewModel=model.getAbcList();
return View(viewModel);
}
Condition: If supposed my list contains n counts. Then if any “native element” of any index hold some value then display other fields and hide vice versa.
i.e.
Something like this
@if (Model.languageList.Any(x => x.nativeLanguage.IsNotEmpty() == false)
{
@LabelFor(x=>x.other)
}
else
{
@LabelFor(x=>x.native)
}
This is not the correct syntax I think (IsNotEmpty is not a valid method).
Tell me the correct way to do this.
You can do it like this