如何检查model.count为null或大于2然后输入codition [英] How to check model.count is null or greater then 2 then enter in codition

查看:167
本文介绍了如何检查model.count为null或大于2然后输入codition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if(Model.Count()< 2)

{



}





亲爱的先生



我想知道如何检查模型。 count = null然后不抛出异常,它进入Codtion内部



我尝试过:



先生,当它获得空值时,条件应该是真的,当model.value = 1然后条件为真,但是当模型时。值= 2然后条件错误





所以请帮助我

if (Model.Count() < 2)
{

}


Dear sir

I Want to Know How to Check if Model. count = null then do not throw exception and it goes in inside of Codtion

What I have tried:

sir when it get null value then condition should true when model.value=1 then condition true but when model. value =2 then condition false


so please help me

推荐答案

试试这个:

Try with this:
if (Model!=null) && (Model.Count<2)) <br />
{<br />
}





解释:只有当模型不为null(fisrt条件)时,如果model.count小于2,则chek



Explanation: only when the model is not null (fisrt condition) chek if the model.count is less than 2


我认为问题是Model是null,而你没有期待。
I think that the problem is that Model is null, and you do not expect that.


这篇关于如何检查model.count为null或大于2然后输入codition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆