您的位置:首页 > 其它

检查对象属性是否有空值

2015-09-14 10:54 381 查看
public ActionResult Create(crm_CompetitiveProducts cp)
{
using (var db = new BaseDbContext())
{
PropertyInfo[] propertys = cp.GetType().GetProperties();
int a = 0;
foreach (var i in propertys)
{
if (i.GetValue(cp) == null)
{
a = a + 1;
}
}
if (a == 0)
{
db.Insert<crm_CompetitiveProducts>(cp);
}
else
{
this.ShowMessage("信息不全", "录入失败");
return RedirectToAction("Create");
}
return RedirectToAction("Index");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: