【问题标题】:How can I redirect to a view when click an html Dropdown list in mvc5?单击mvc5中的html下拉列表时如何重定向到视图?
【发布时间】:2017-11-06 12:56:48
【问题描述】:

我正在开发一个医疗应用程序。我有下拉列表包括患者姓名。单击下拉列表时,如何重定向到显示所选患者生命体征的视图。我使用实体框架将数据绑定到下拉列表。

        this is what I did.


        //Controller

        public ViewResult PatientLIstView()
    {
        PatientListdbEntities dbcontext = new PatientListdbEntities();
        var getPatientlist = dbcontext.Patient_Reg.ToList();
        SelectList list = new SelectList(getPatientlist, "Preg_id", "P_Name");
        ViewBag.patients = list;

        return View();
    }

    // this is the view


    @{
ViewBag.Title = "PatientLIstView";
Layout = "~/Views/Shared/_Layout.cshtml";
 }



   <div class="page-content-wrapper">
    <div class="page-content">
      <table align="center" style="margin-top:8%;margin-left:18%">

        <tr>
        <td>Patient List</td>
        <td>@Html.DropDownList("paients1", ViewBag.patients as SelectList, 
  "---select---")</td></tr>
    </table>
   @*@Html.DropDownList("paients1", ViewBag.patients as SelectList, "---
    select---", new { style = "height: 100px;" })*@

     </div>
  </div>

现在我有了患者名单。如何在控制器中获取下拉选择的值,以便我可以在另一个视图中显示相应的患者信息?

【问题讨论】:

  • 您需要 javascript 来响应客户端事件(或者只需将表单提交给重定向到页面的方法)

标签: c# asp.net asp.net-mvc asp.net-mvc-5


【解决方案1】:

您可以使用这条线路,这会调用您控制器中的其他方法来搜索并显示您的患者 ID 信息。

@Html.DropDownList(@Html.ActionLink("Edit", actionname, controllername, new { Id = Patient }), ViewBag.patients as SelectList, 
"---select---")'

如果您还有其他问题,请告诉我。

【讨论】:

  • 我应该将“actionname”和“controllername”作为字符串给出,如果不告诉如何做到这一点以及“new { Id = Patient }”是什么意思。我是 MVC 的初学者。这就是为什么我要这样问。
  • 你使用数据库吗?
  • 是的。我正在使用实体框架来绑定 dropdowm。 “Preg_id”是下拉列表的值,“P_Name”是要显示的文本。
  • 好的,你可以新建一个页面,调用这个PatientInfo。现在你可以设置这条线而不是你的。 @Html.DropDownList(@Html.ActionLink("PatientName", "PatientInfo", "controllerclass", new { Id = Preg_id}), ViewBag.patients as SelectList, "---select---")'
  • 它不起作用。显示 Preg_id 在当前上下文中不存在
猜你喜欢
  • 2014-09-22
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-19
  • 2017-07-06
  • 1970-01-01
相关资源
最近更新 更多