我在C#中进行linq查询并且一切顺利但是当我在MVC中调用此方法时它崩溃了,它不接受空值我想要空值是" "
var referralDocs = (from d in _dc.ReferralDoctors
join mlog in _dc.LogPS.Where(x => x.id_action == 1)
on d.ReferralDoctorID equals mlog.id_PS into mlog
join _Category in _dc.ReferringDoctorCategories
on d.ReferringDoctorsCategory equals _Category.CategoryID into CatGroup
from _Category in CatGroup.DefaultIfEmpty()
where
d.DoctorID == doctorID && d.isDeleted == false && (d.NotificationEmail.Replace(" ", "").ToLower().Contains(search)
|| d.PracticePhone.Replace(" ", "").ToLower().Contains(search) || d.LastName.Replace(" ", "").ToLower().Contains(search) || d.FirstName.Replace(" ", "").ToLower().Contains(search))
select new ReferralDoctorInfo()
{
BirthDate = d.BirthDate,
DoctorID = d.DoctorID,
FirstName = d.FirstName != null ? d.FirstName.Trim().Replace("\r\n", "").Replace("\r", "").Replace("\n", "") : "",
HasOptOutNews = d.HasOptOutNews,
isDeleted = d.isDeleted,
LastName = d.LastName != null ? d.LastName.Trim().Replace("\r\n", "").Replace("\r", "").Replace("\n", "") : "",
NotificationEmail = d.NotificationEmail != null ? d.NotificationEmail.Trim().Replace("\r\n", "").Replace("\r", "").Replace("\n", "") : "",
PracticePhone = d.PracticePhone,
PracticeName = d.PracticeName != null ? d.PracticeName.Trim().Replace("\r\n", "").Replace("\r", "").Replace("\n", "") : "",
ReferralDoctorID = d.ReferralDoctorID,
lastOptOutDatetime = mlog.Where(x => x.client_id == doctorID && x.id_PS == d.ReferralDoctorID).Max(y => y.date),
DoctorCategory = _Category
});
好的我在select:DoctorCategory = _Category
中有这个当我在MVC中获取此对象时,此对象的第一行具有对象应具有的所有值并且工作正常但第二行没有值,因此它给出了空值,这是我想要的好有那些没有类别但在那一点崩溃的人,因此我希望他们成为" "
我想在DefaultifEmpty或_Category中使用允许我更改空值的内容
类似这样的事情
ReferingDoctorCategory = _Category.Name != null ? _Category.Name : "",
这个问题是对象无效,所以我无法使用它
答案 0 :(得分:1)
如果有人想和我一样,我找到了答案
@foreach ($categories as $category)
<option value="{{ $category->id }}" placeholder="choose parent category">{{ $category->name }}</option>
@endforeach
这并没有将每一行为空的行改为&#34;&#34;但它确实把每个人都空了,这样MVC就不会崩溃