如何解决在Controller
public class MyLeave
{
public int Leave_id { get; set; }
public string EmpID { get; set; }
[Display(Name = "From :")]
//[DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}",ApplyFormatInEditMode = true)]
[Required]
public DateTime FromDate { get; set; }
[Display(Name = "Till :")]
//[DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}",ApplyFormatInEditMode = true)]
[Required]
public DateTime TillDate { get; set; }
[Display(Name = "Total Number Of Days :")]
[Required]
public int TotalDays { get; set; }
[Display(Name = "Reason :")]
[Required]
public string Reason { get; set; }
public string Status { get; set; }
public string Comment { get; set; }
public List<MyLeave> LeaveData { get; set; }
}
公共类LeaveManagementController:控制器 { // GET:LeaveManagement
public ActionResult ApplyLeave()
{
return View();
}
public ActionResult SubmitLeave(MyLeave obj)
{
string SessionEmployeeID = Session["EmployeeID"].ToString();
string con = System.Configuration.ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
SqlConnection cnn = new SqlConnection(con);
SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "sp_Leave";
cmd.Parameters.AddWithValue("@EmpID",SessionEmployeeID);
cmd.Parameters.AddWithValue("@FromDate",obj.FromDate); null
cmd.Parameters.AddWithValue("@TillDate",obj.TillDate); null
cmd.Parameters.AddWithValue("@TotalDays",obj.TotalDays);
cmd.Parameters.AddWithValue("@Reason",obj.Reason);
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
TempData["LeaveAppMessage"] = "Application Submitted To Admin Successfully!";
return RedirectToAction("ApplyLeave");
}
}
@model WebTimeSheetManagement.Models.MyLeave
@using(Html.BeginForm(“ MyLeave”,“ LeaveManagement”)) {
<div>
@Html.LabelFor(model => model.FromDate,htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.FromDate,new { htmlAttributes = new { @class = "datepicker form-control",value = "myFromDate",id = "datepicker1",required = "required" } })
@Html.ValidationMessageFor(model => model.FromDate)
</div>
<div>
@Html.LabelFor(model => model.TillDate,htmlAttributes: new { @class = "control-label " })
@Html.EditorFor(model => model.TillDate,value = "myTillDate",id = "datepicker2",required = "required" } })
@Html.ValidationMessageFor(model => model.TillDate)
</div>
<br />
<div>
@Html.LabelFor(model => model.TotalDays,htmlAttributes: new { @class = "control-label " })
@Html.TextBoxFor(model => model.TotalDays,new { @class = "form-control",@maxlength = 40,id = "Calculate",required = "required" })
@Html.ValidationMessageFor(model => model.TotalDays)
</div>
<br />
<div class="form-group ">
@Html.LabelFor(model => model.Reason,htmlAttributes: new { @class = "control-label" })
@Html.TextAreaFor(model => model.Reason,@onkeypress = "",required = "required",col = 4,row = 10})
@Html.ValidationMessageFor(model => model.Reason)
</div>
<br />
<input type="submit" class="btn btn-success" id="btn_apply" value="Apply" onclick="location.href='@Url.Action("SubmitLeave","LeaveManagement","")'" />
}
日期选择器返回null 原因也返回null 请在2-3天后尽快解决 日期选择器返回日期,例如01/01/0001
解决方法
您必须使日期参数可为空。对于从DateTime
到DateTime?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。