如何在视图页面上显示两个不同的数据库查询 [英] How do I show two different database query on the view page

查看:73
本文介绍了如何在视图页面上显示两个不同的数据库查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查询数据库并在同一页面上显示两个结果

I am trying to query my database and show two results on the same pages

var datafalse = (from u in _db.aspnet_Users
                                  join d in _db.Doctors on u.UserId equals d.UserId
                                  join p in _db.Patients on d.DoctorsId equals p.DoctorsId
                                  where u.UserName == User.Identity.Name && p.reviewed == false
                                  orderby p.ClientID
                                  select
                                       new PatientsModel
                                            {
                                                 PatientsId = p.PatientsId,
                                                 ClientID = p.ClientID,
                                                 DOB = p.DOB,
                                                 Gender = p.Gender,
                                                 Handedness = p.Handedness,
                                                 RecordingDate = p.RecordingDate,
                                                 TimeRecording = p.TimeRecording
                                            }).ToList();

                       var datatrue = (from u in _db.aspnet_Users
                                  join d in _db.Doctors on u.UserId equals d.UserId
                                  join p in _db.Patients on d.DoctorsId equals p.DoctorsId
                                  where u.UserName == User.Identity.Name && p.reviewed == false
                                  orderby p.ClientID
                                  select
                                       new PatientsModel
                                       {
                                            PatientsId = p.PatientsId,
                                            ClientID = p.ClientID,
                                            DOB = p.DOB,
                                            Gender = p.Gender,
                                            Handedness = p.Handedness,
                                            RecordingDate = p.RecordingDate,
                                            TimeRecording = p.TimeRecording
                                       }).ToList();



查看/html页面.



view/html page.

h2>Doctors Submitted List Patients </h2>
<hr />
<div>
<h2>Submitted Request need to be reviewed </h2>
<p>
<table>
<tr>
<th>Client ID</th>
<th>DOB</th>
<th>Gender</th>
<th>Handedness</th>
<th>Date of Recording</th>
@*<th>Time of Recording</th>*@
<th>View Details</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.ClientID)</td>
<td>@Html.DisplayFor(modelItem => item.DOB)</td>
<td>@Html.DisplayFor(modelItem => item.Gender)</td>
<td>@Html.DisplayFor(modelItem => item.Handedness)</td>
<td>@Html.DisplayFor(modelItem => item.RecordingDate)</td>
@*<td>@Html.DisplayFor(modelItem => item.TimeRecording)</td>*@
<td>@Html.ActionLink("Details", "Details", new { id = item.PatientsId })
</td>
     </tr>
}
</table>
</p>
</div>
<hr />
<div>
    
     <h2>Reports are that was reveiwed.</h2>
          <p>
               <table>
                    <tr>
                         <th>Client ID</th>
                         <th>DOB</th>
                         <th>Gender</th>
                         <th>Handedness</th>
                         <th>Date of Recording</th>
                         <th>View Details</th>
                    </tr>
                    @foreach (var item in Model)
                    {
                         <tr>
                              <td>@Html.DisplayFor(modelItem => item.ClientID)</td>
                              <td>@Html.DisplayFor(modelItem => item.DOB)</td>
                              <td>@Html.DisplayFor(modelItem => item.Gender)</td>
                              <td>@Html.DisplayFor(modelItem => item.Handedness)</td>
                              <td>@Html.DisplayFor(modelItem => item.RecordingDate)</td>
                              @*<td>@Html.DisplayFor(modelItem => item.TimeRecording)</td>*@
                              <td>@Html.ActionLink("Details", "Details", new { id = item.PatientsId })
                              </td>
                         </tr>
                    }
               </table>

          </p>

</div>

推荐答案



我的建议是只检索所有数据并将其存储在viewdata或模型中

在设计方面,您需要编写简单的if条件来检查是对还是错

希望您在"PatientsModel"模型中拥有已审核"属性
如果您拥有它,那么显示起来很简单

Hi

My suggestion is just retrieve all data and store it in viewdata or model

in design side you need to write simple if condition to check which is true or false

I hope you''ve "reviewd" property in "PatientsModel" Model
If you ''ve it then its simple to display

@foreach (var item in Model)
                    {
if(item.reviewed)
{
                         <tr>
                              <td>@Html.DisplayFor(modelItem => item.ClientID)</td>
                              <td>@Html.DisplayFor(modelItem => item.DOB)</td>
                              <td>@Html.DisplayFor(modelItem => item.Gender)</td>
                              <td>@Html.DisplayFor(modelItem => item.Handedness)</td>
                              <td>@Html.DisplayFor(modelItem => item.RecordingDate)</td>
                              @*<td>@Html.DisplayFor(modelItem => item.TimeRecording)</td>*@
                              <td>@Html.ActionLink("Details", "Details", new { id = item.PatientsId })
                              </td>
                         </tr>
                    }
}



因此您只能在一个节目中显示true,而在另一个节目中显示false

我希望你能理解我说的

最好的



so you can display only true in one show and false in another show

I hope you understood wht I said

All the Best


这篇关于如何在视图页面上显示两个不同的数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆