我已确认对控制器中的操作方法的发布请求正确。当我在控制器中设置一个断点时,它没有命中。为什么会这样呢?我相信我的HTML也是正确的。
ManageClients.cshtml
@using OPP.Web.ViewModels
@model AdminViewModel
@{
ViewBag.Title = "Manage Clients";
}
<h2>Manage Clients</h2>
<table class="table table-bordered table-responsive table-hover">
<tr>
<th>Client ID </th>
<th>Client Name </th>
<th>Client Expiration Date</th>
<th>Facility Code</th>
<th>Client Email</th>
<th>Is the client Active?</th>
</tr>
@foreach (Client client in Model.Clients)
{
<tr>
<td>@Html.ActionLink(client.client_id.ToString(), "Index", "Clients", new { id = client.client_id }, null)</td>
<td>@client.Name</td>
<td>
@client.ExpireDate
@if (client.ExpireDate != null)
{
using (Html.BeginForm("UpdateExpireTime", "Clients"))
{
<label>Add days (28 is 4 weeks)</label>
@Html.TextBoxFor(m => m.Client.Days, new { @class = "form-control" })
@Html.TextBoxFor(m => m.Client.client_id, new { @Value = client.client_id, @class = "hidden" })
@*<input type="button" value="Delete" onclick="location.href='@Url.Action("Delete", "Workouts")'" />*@
<input type="submit" value="Update Time" />
}
}
</td>
<td>@client.FacilityCode</td>
<td>@client.Email</td>
<td>@client.Active</td>
<td>
@using (Html.BeginForm("Delete", "Clients"))
{
@Html.TextBoxFor(m => m.Client.client_id, new { @Value = client.client_id, @class = "hidden" })
@*<input type="button" value="Delete" onclick="location.href='@Url.Action("Delete", "Workouts")'" />*@
<input type="submit" value="Revoke access" />
}
</td>
</tr>
}
</table>
<h2>Manually make a client active (28 day subscription)</h2>
@using (Html.BeginForm("ManualActiveAdd", "Clients",FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<label>Client ID:</label>
@Html.TextBoxFor(m => m.Client.client_id, new { @class = "form-control" })
@*<input type="button" value="Delete" onclick="location.href='@Url.Action("Delete", "Workouts")'" />*@
<input type="submit" value="Give 4 week access" />
}
客户端控制器
[HttpPost]
public ActionResult Delete(Client client)
{
if(Request.IsAuthenticated)
{
if(User.IsInRole("Superuser"))
{
using(OPPDBContext context = new OPPDBContext())
{
Client nclient = context.Clients.Where(p => p.client_id == client.client_id).FirstOrDefault();
nclient.Active = false;
nclient.IsAssessment = false;
nclient.IsSurvey = false;
nclient.ExpireDate = null;
context.Clients.AddOrUpdate(nclient);
}
return RedirectToAction("ManageClients", "Admin");
}
}
return RedirectToAction("AccessDenied", "Error");
}
[HttpPost]
public ActionResult UpdateExpireTime(Client client)
{
if (Request.IsAuthenticated)
{
if (User.IsInRole("Superuser"))
{
using (OPPDBContext context = new OPPDBContext())
{
Client nclient = context.Clients.Where(p => p.client_id == client.client_id).FirstOrDefault();
nclient.ExpireDate = nclient.ExpireDate.Value.AddDays(client.Days);
context.Clients.AddOrUpdate(nclient);
context.SaveChanges();
}
return RedirectToAction("ManageClients", "Admin");
}
}
return RedirectToAction("AccessDenied", "Error");
}
[HttpPost]
public ActionResult ManualActiveAdd(Client client)
{
if (Request.IsAuthenticated)
{
if (User.IsInRole("Superuser"))
{
using (OPPDBContext context = new OPPDBContext())
{
Client nclient = context.Clients.Where(p => p.client_id == client.client_id).FirstOrDefault();
nclient.Active = true;
nclient.IsAssessment = true;
nclient.IsSurvey = true;
nclient.ExpireDate = DateTime.Now.AddDays(28);
context.Clients.AddOrUpdate(nclient);
}
return RedirectToAction("ManageClients", "Admin");
}
}
return RedirectToAction("AccessDenied", "Error");
return View();
}
如果我的发帖请求/控制者是正确的,可能是什么问题?