/*Class definition*/
public class ConcreteClassModel : BaseModel
{
...
public bool IntersectsWith(ConcreteClassModel ccm)
{
ccm.StartDateDT = DateTime.Parse(ccm.StartDate);
ccm.EndDateDT = DateTime.Parse(ccm.EndDate);
this.StartDateDT = DateTime.Parse(this.StartDate);
this.EndDateDT = DateTime.Parse(this.EndDate);
return !(this.StartDateDT > ccm.EndDateDT || this.EndDateDT < ccm.StartDateDT);
}
}
/*Inside Controller Method*/
List<ConcreteClassModel> periods = LoadAllByParameters<ConcreteClassModel>(
ccm.CoverId, x => x.CoverId,
ccm.SectionId, x => x.SectionId);
var intersectingPeriods =
periods.Where(x => x.IntersectsWith(ccm));
StringBuilder partReply = intersectingPeriods.Aggregate(new StringBuilder(), (a, b) => a.Append(b));
********if (!partReply.ToString().IsNullOrEmpty())***************************
{
string reply =
"<div id='duplicateErrorDialog' title='Duplication Error'><span> Duplicate Period(s)</br>" +
partReply + "</span></ div >";
return Json(reply, JsonRequestBehavior.AllowGet);
}
return Json(null, JsonRequestBehavior.AllowGet);
以上似乎工作正常,如果没有找到重复的日期期间,空响应将触发我的 javascript 保存。但是可以使用: if (!partReply.ToString().IsNullOrEmpty()) As StringBuilder 没有自己的 .IsNullOrEmpty() 等价物吗?我能找到的每条评论、问题等都只与字符串有关,在 MSDN 上看不到任何东西!