[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "ID,FromTime,ToTime,CustomerID,UserID,Description,Type,CreatedTime")] Schedule schedule)
{
if (ModelState.IsValid)
{
db.Entry(schedule).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.CustomerID = new SelectList(db.Customers, "ID", "Name", schedule.CustomerID);
ViewBag.UserID = new SelectList(db.Users, "ID", "Name", schedule.UserID);
//return View(schedule);
return RedirectToRoute("Default", new { controller = "Schedules", action = "Index" });
}
<div class="form-group">
@Html.LabelFor(model => model.FromTime, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FromTime, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FromTime, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ToTime, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ToTime, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ToTime, "", new { @class = "text-danger" })
</div>
</div>
FromTime
and的类型ToTime
很长,我想将其显示为时间,然后将其保存回来。
如果我在数据库中有一种 long 类型,我需要在 Model View Controller ASP.Net 中将其显示为 Time ,然后将其作为 long 再次保存到数据库中。我怎样才能做到这一点?