Razor MVC是两个整数的加法吗?

Razor MVC是两个整数的加法吗?,razor,Razor,否的父母: @{ foreach (var item in Model) { ((item.Mothers.Count) + (item.Fathers.Count)).ToString(); } } @{ foreach (var item in Model) { item.Mothers.Count +item.Fathers.Count } } O/p:No的父母: 否的父母: @{ foreach (var item in Model)

否的父母:

@{
   foreach (var item in Model)
   {
  ((item.Mothers.Count) + (item.Fathers.Count)).ToString();
   }
}
@{
foreach (var item in Model)
   {
 item.Mothers.Count +item.Fathers.Count
   }
}
O/p:No的父母:

否的父母:

@{
   foreach (var item in Model)
   {
  ((item.Mothers.Count) + (item.Fathers.Count)).ToString();
   }
}
@{
foreach (var item in Model)
   {
 item.Mothers.Count +item.Fathers.Count
   }
}
O/p:No的父级:0+0

我试图像这样显示o/p,如果未找到父/母信息,则显示为零,如果存在父/母信息,则显示附加的mother.count()+father.count()


我在做什么?

您可以检查两个实体的总和是否为0,然后对结果采取行动

如果父项和母项均为0,则将写入“无父项”。否则,它将写入家长人数

@{
   foreach (var item in Model)
   {
    if(item.Mothers.Count == 0 && item.Fathers.Count == 0)
    {
        response.write("no parents");
    }else{
        response.write(((item.Mothers.Count) + (item.Fathers.Count)).ToString());
    }
   }
}
它不工作!为什么?

No的父项:@{((item.Mothers.Count())+(item.Fathers.Count()).ToString();}

}
当你说它有效或无效时,你是什么意思?你是说它不会编译吗?你的意思是你得到一个运行时错误?你得到了什么错误?它有效吗?给我O/P No的父母:2它不工作?给我O/P:No的父项://empty显示两种情况均未发生错误。
            No's Parents :@{ ((item.Mothers.Count()) +   (item.Fathers.Count())).ToString ();} 

            <hr />
    </div>
}