我正在尝试根据我在View中的复选框更新我的数据库。 我想要它做的是当我单击“提交”以将表单传递给HttpPost destroyMultipleBoxesUpload时,如果选中它,则将数据库布尔'destoryed'更新为true。
这是我的控制器
[Authorize]
public ActionResult destroyMultipleBoxes()
{
var daybreakDB = new daybreakEntities3();
List<box> list = daybreakDB.boxes.ToList();
ViewBag.TodaysDate = DateTime.Today;
return View(list);
}
[Authorize]
[HttpPost]
public ActionResult destroyMultipleBoxesUpload(HttpPostedFileBase file, FormCollection destroyBoxes)
{
return RedirectToAction("Index");
}
现在,destroyMultipleBoxesUpload什么也没做。
我的观点:
@model List<DaybreakRecordsArchive.Models.box>
@{
ViewBag.Title = "destroyMultipleBoxes";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Destroy Multiple Boxes</h2>
<p>
This webpage only loades boxes that are eligible for destruction.
</p>
<p>
Please upload the destruction certificate then select the boxes that were destroyed under this certificate and click "Destroy".
</p>
@using (Html.BeginForm("destroyMultipleBoxesUpload", "Box", FormMethod.Post))
{
<label for="file" id="imageLabel">Upload Image:</label>
<input type="file" name="file" id="fileChoose" style="width: 100%;" />
<table class="table">
<th>
Destroy
</th>
<th>
BoxId
</th>
<th>
Label Id
</th>
@foreach(var item in Model)
{
if (item.destruction_date < ViewBag.TodaysDate)
{
<tr>
<td>
@Html.CheckBoxFor(modelItem => item.destroyed, false)
</td>
<td>
@Html.DisplayFor(modelItem => item.id)
@Html.HiddenFor(modelItem => item.id)
</td>
<td>
@Html.DisplayFor(modelItem => item.labelId)
@Html.HiddenFor(modelItem => item.labelId)
</td>
</tr>
}
}
<tr>
<td>
<input type="submit" name="Submit" value="Destroy" />
</td>
</tr>
</table>
}
显示我的数据库框,并显示与被称为销毁的bool链接的复选框以及2个不同的标识符。
public partial class box
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public box()
{
this.residents = new HashSet<resident>();
this.transitions = new HashSet<transition>();
}
public int id { get; set; }
public Nullable<int> @class { get; set; }
[DataType(DataType.Date)]
public Nullable<System.DateTime> creation_date { get; set; }
[DataType(DataType.Date)]
public Nullable<System.DateTime> destruction_date { get; set; }
public string owner { get; set; }
public Nullable<int> facility { get; set; }
public string description { get; set; }
public bool destroyed { get; set; }
public Nullable<int> current_location { get; set; }
public string dest_img_path { get; set; }
public string labelId { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<resident> residents { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<transition> transitions { get; set; }
public virtual @class class1 { get; set; }
public virtual storage_location1 storage_location { get; set; }
public virtual facility facility1 { get; set; }
}