【发布时间】:2020-11-20 22:42:13
【问题描述】:
您好,我不知道如何将简单数据从 View 传递到 Controller,我需要生成更新相同 View 的值,让我展示代码以便更好地理解。我想添加包含患者、医生和就诊日期(日期和时间)的就诊,所以在创建页面中我得到了代码:
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="PatientId" class="control-label"></label>
<select asp-for="PatientId" class="form-control" asp-items="ViewBag.PatientId"></select>
</div>
<div class="form-group">
<label asp-for="DoctorId" class="control-label"></label>
<select asp-for="DoctorId" id="iddoctor" class="form-control" asp-items="ViewBag.DoctorId" onchange="go()">
</select>
</div>
<div class="form-group">
<label asp-for="date" class="control-label"></label>
<input asp-for="date" class="form-control" />
<span asp-validation-for="date" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="date" class="control-label"></label>
<select asp-for="date" class="form-control" asp-items="ViewBag.date"></select>
</div>
我从日历中选择患者、医生和日期,并将其发送到控制器,控制器应生成可用时间列表以放入 ViewBag.date 中的同一页面,这样我也可以选择时间并通过单击“添加”完成添加访问访问”
我的控制器创建函数
public IActionResult Create()
{
ViewData["DoctorId"] = new SelectList(_context.Doctors, "DoctorId", "Surname" );
ViewData["PatientId"] = new SelectList(_context.Patients, "PatientId", "Surname" );
return View();
}
编辑: 下面我的答案中的解决方案
【问题讨论】:
标签: ajax asp.net-core-mvc