我希望用户在表单中插入日期。你能告诉我如何在我的视图中插入日期。每当我在表单中输入值时,都会出现此错误。
我的PlaneSchedule模型如下。
public class Plane_Schedule
{
[Key]
public int Plane_id { get; set; }
public int PlaneSch_id { get; set; }
public string Plane_LocTo { get; set; }
public string Plane_LocFrom { get; set; }
public DateTime Time_Dep { get; set; }
public DateTime Time_Arrive { get; set; }
public virtual List<Ticket> Tickets { get; set; }
}
Controller中的操作如下
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SaveSchedule(AirlineWebApplication.Models.Plane_Schedule Plane_Schedule, HttpPostedFileBase file)
{
db.Plane_Schedule.Add(Plane_Schedule);
db.SaveChanges();
return RedirectToAction("Index");
}
PlaneSchedule视图如下
<section class="registersection">
<div class="container-fluid">
<div class="row">
<div class="signupForm">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<form action="~/Plane_Schedule/SaveSchedule" method="post">
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.AntiForgeryToken()
<div class="Form1">
<div class="row">
<div class="form-group col-sm-4">
<div class="editor-field">
<label>
FROM
@Html.EditorFor(model => model.Plane_LocFrom)
</label>
@Html.ValidationMessageFor(model => model.Plane_LocFrom)
</div>
</div>
<div class="form-group col-sm-4">
<div class="editor-field">
<label>
TO
@Html.EditorFor(model => model.Plane_LocTo)
</label>
@Html.ValidationMessageFor(model => model.Plane_LocTo)
</div>
</div>
</div>
</div>
<p>
<input type="submit" value="Register" />
</p>
}
</form>
</div>
</div>
</div>
</div>
</section>
请告诉我如何在视图模型中插入用户的日期并将其保存在数据库中?