gpt4 book ai didi

javascript - 单击按钮后更改 bool 值的状态

转载 作者:行者123 更新时间:2023-12-03 02:38:08 27 4
gpt4 key购买 nike

开发用于约会的 C# 应用程序。我希望管理员能够进入详细信息页面并单击按钮来确认约会,这是一个设置为 false 的 bool 值来启动。单击后,我将重新加载页面并确认预约。

我无法理解如何实现这一目标。

这是我的 Controller :

    [HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Details([Bind(Include = "AppointmentId,Confirmed")] Appointments appointments)
{
if (ModelState.IsValid)
{
db.Entry(appointments).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Details", new { id = appointments.AppointmentId });
}

return View(appointments);
}

以及我想要执行此部分的详细信息页面:

<th>
@Html.DisplayName("Appointment Status")
</th>
@if (Model.Confirmed == false)
{
<td>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Confirm Appointment" class="btn btn-default" />
</div>

</div>
</td>
}
else if (Model.Confirmed == true)
{
<td>
@Html.DisplayName("Appointment Confirmed")
</td>
}
</tr>

我一整天都在这个项目上,所以也许疲惫的眼睛在玩弄我

最佳答案

看起来您已经完成大部分工作了。但是您的提交按钮需要位于将再次发回的表单内。

这是一种方法,它会发布到服务器上的特定“ConfirmApppointment”操作方法,该方法将确认约会(因为这似乎是您要更新的唯一字段,因此实际上不需要发回)整个预约模式)。

我认为您还需要将约会 ID 放在隐藏字段中,以便将其发送回服务器,以便知道要确认哪个约会:

详细信息 View 将如下所示:

<th>Appointment Status</th>
@if (Model.Confirmed == false)
{
<td>
@using (Html.BeginForm("ConfirmAppointment", "Appointment", FormMethod.Post))
{
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Confirm Appointment" class="btn btn-default" />
<input type="hidden" name="appointmentID" value="@Model.Id"/>
</div>
</div>
}
</td>
}
else if (Model.Confirmed == true)
{
<td>Appointment Confirmed</td>
}

在您的 Controller 中(我假设您的 Controller 称为“Appointments”,但如果不是,请在 Html.BeginForm 中修改它):

//this method is just for displaying your Details view. I'm not sure how exactly your code gets to here, since you didn't specify much (apart from a button gets clicked), so if the method signature is wrong, that'll be something for you to fix yourself, or ask another question about
public ActionResult Details(Appointments appointment)
{
return View(appointment);
}

//this method receives the postback when the "Confirm Appointment" button is pressed, and updated the appointment details. Then it returns to the user to the same screen, where this time they should see the "Appointment Confirmed" message instead of the button
[HttpPost]
public ActionResult ConfirmAppointment(int appointmentID)
{
var appt = db.Appointments.Find(appointmentID);
appt.Confirmed = true;
db.SaveChanges();
return View(appt);
}

关于javascript - 单击按钮后更改 bool 值的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48453199/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com