[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
和ToTime
的类型很长,我希望将其显示为时间,然后将其保存一段时间。
如果我在数据库中有一个long类型,我需要在模型视图控制器ASP.Net中将其显示为Time,然后将其再次保存到数据库中。我怎么能这样做?