如何通过选定的样本获取示例详细信息?

发布于 2025-02-11 03:18:21 字数 2141 浏览 0 评论 0原文

例如,我需要获取示例详细信息取决于选定的样本 单击示例1的详细信息显示其详细信息和样本2,依此类推 我混淆了如何做到这一点,我在MVC中是新手:

这是控制器代码:

 public ActionResult Index()
        {
            int UserId = Convert.ToInt32(Session["UserID"]);
            var samples = _context.hospital_programs.Where(x => x.hospital_id == UserId).ToList();
            return View(samples);
           
        }

这是图像ID示例名称中的输出图像列:

“

这是视图代码:

<table class="table">
    <tr>
        <th>
            
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Program.name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.sample.id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.sample.name)
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
           
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Program.name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.sample.id)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.sample.name)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
            @Html.ActionLink("Details", "Details", new { id=item.id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.id })
        </td>
    </tr>
}

</table>

这是详细信息控制器代码:

 public ActionResult Details(int id )
        {
          
            int UserId = Convert.ToInt32(Session["UserID"]);
            var results = _context.RESULTS.Where(r => r.custid == UserId).ToList();
            return View(results);
        }

现在在详细信息中,当我单击示例的详细信息1时,它显示了所有样本的结果 如何更新代码以仅查看示例1结果或样本2结果仅

在我要添加samemid =选定样品的地方?

I need to get sample details depends on selected sample for example
when click on details of sample 1 show its details and sample 2 and so on
I confused how to do that I am new in MVC :

This is the controller code :

 public ActionResult Index()
        {
            int UserId = Convert.ToInt32(Session["UserID"]);
            var samples = _context.hospital_programs.Where(x => x.hospital_id == UserId).ToList();
            return View(samples);
           
        }

this is the output image columns in image Id Sample Name:

enter image description here

this is the view code :

<table class="table">
    <tr>
        <th>
            
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Program.name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.sample.id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.sample.name)
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
           
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Program.name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.sample.id)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.sample.name)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
            @Html.ActionLink("Details", "Details", new { id=item.id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.id })
        </td>
    </tr>
}

</table>

This is the details controller code :

 public ActionResult Details(int id )
        {
          
            int UserId = Convert.ToInt32(Session["UserID"]);
            var results = _context.RESULTS.Where(r => r.custid == UserId).ToList();
            return View(results);
        }

In the details now when I click details for sample 1 it shows results for all samples
how can I update the code to view only sample 1 results or sample 2 results only

where I will add sampleId = selected sample ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走野 2025-02-18 03:18:21

我找到了解决方案:

用sample_id替换ID

 @Html.ActionLink("Details", "Details", new { id=item.id })

 @Html.ActionLink("Details", "Details", new { id=item.sample_id }) 

I found the solution :

replace id with sample_id

 @Html.ActionLink("Details", "Details", new { id=item.id })

 @Html.ActionLink("Details", "Details", new { id=item.sample_id }) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文