ExtJs+C#.net+linq做的项目,有一个Grid加载不出数据,查看了原来是因为有一个字段里返回数据有换行符导致的,捣鼓了好久弄出来了,返回字段时将换行替换就行了:str.Replace(System.Environment.NewLine, @"/r/n")
protected string GetSick()
{
string JsonString = string.Empty;
string RowString = string.Empty;
IQueryable<CHECK_CheckSickList> result;
var rt = from p in sysd.CHECK_CheckSickList orderby p.SID descending select p;
result = rt.Where(m => true);
if (!string.IsNullOrEmpty(_SickName) && !string.IsNullOrEmpty(_QueryClass))
{
switch (_QueryClass)
{
case "1":
result = result.Where(m => m.SickName.Contains(_SickName));
break;
case "2":
result = result.Where(m => m.SID == Convert.ToInt32(_SickName));
break;
case "3":
result = result.Where(m => m.SickZJM.Contains(_SickName));
break;
}
}
else if (!string.IsNullOrEmpty(_SickName))
{
result = result.Where(m => m.SickName.Contains(_SickName));
}
if (!string.IsNullOrEmpty(_GroupCode))
result = result.Where(x => x.OID == Convert.ToInt32(_GroupCode));
string RecordCount = result.Count().ToString();
if (string.IsNullOrEmpty(_start))
result = result.Take(CCommon.nRowsCount);
else
result = result.Skip(Convert.ToInt32(_start)).Take(CCommon.nRowsCount);
JsonString += "{count:" + RecordCount + ",rows:[";
foreach (var rst in result)
{
RowString += "{SID:'" + rst.SID
+ "',SickName:'" + rst.SickName
+ "',OID:'" + rst.OID
+ "',SickZJM:'" + rst.SickZJM
+ "',IsSick:'" + rst.IsSick
+ "',IsNomalSick:'" + rst.IsNomalSick
+ "',IsCount:'" + rst.IsCount
+ "',SickMind:'" + (!string.IsNullOrEmpty(rst.SickMind) ? rst.SickMind.Trim().Replace(System.Environment.NewLine, @"/r/n") : "")
+ "'},";
}
if (RowString.Length > 0)
RowString = RowString.Substring(0, RowString.Length - 1);
JsonString += RowString + "]}";
return JsonString;
}