【发布时间】:2011-09-28 21:25:39
【问题描述】:
由于某种原因,当我在这段代码中添加三元 if 语句时,会引发 NullPointerException。我不太清楚为什么……有什么想法吗?这是 jqGrid 的方法 - 返回 Json 数据。
var gridModel = from entity in vendorList.AsQueryable()
select new
{
VendorId = "<a href='/Admin/DetailsPlan/" + entity.VendorId + "'><img src='/Images/next_icon_sm.png' class='icon' alt='View Vendor' /></a>",
VendorNm = entity.VendorNm,
Phone = (entity.Phone.Length < 5) ? String.Format("{0:(###) ###-####}", Convert.ToInt64(entity.Phone)) : entity.Phone,
City = entity.City,
State = entity.LkState.StateAbbr
};
你不能在那个位置有一个三元 if 语句吗?
【问题讨论】:
-
什么是“一元”if 语句?
-
@Peter:一个例子是 i++; OP 显然没有问题。我认为我们的好医生正在寻找的词是三元。 en.wikipedia.org/wiki/Ternary_operation 更正。
-
? :被称为 条件运算符。(它实际上是三元,而不是一元。)msdn.microsoft.com/en-us/library/ty67wk28.aspx
标签: c# jquery asp.net-mvc-2 jqgrid if-statement