我尝试从包含在HTML表单中的Bootstrap datepicker传递日期到ASP.NET MVC3控制器。问题是,当我选择过去的日期时,传递给控制器的模型具有正确值填充的适当DateTime字段。然而,当我选择现在或未来的日期时,StartDate DateTime字段显示为0001-01-01。
以下是视图代码:
我找不到有类似问题的人。
@using (Ajax.BeginForm("AddNewActivity", "Home", null, new AjaxOptions
{
HttpMethod = "Post",
UpdateTargetId = "activitiesTableDiv",
InsertionMode = InsertionMode.Replace,
OnBegin = "disableButton"
}))
{
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-label">
Start date
</div>
<div class="editor-field">
<input id="StartDate" data-date-format="dd-mm-yyyy" class="pickDate form-control valid"
type="text" name="StartDate" data-val-required="The StartDate field is required."
data-val="true" />
@Html.ValidationMessageFor(model => model.StartDate)</div>
</fieldset>
}
控制器端 - POST方法:
public ActionResult AddNewActivity(ActivityModel model, FormCollection collection)
{
var test = model.StartDate;
if (model.ObjectId == null)
objectid = model.ObjectId;
var jury = model.UserIds.Split(';').ExtractInt32();
string[] emails = jury.Select(i => Storage.UserGetById(i).Email).ToArray();
if (model.UserIds.Length > 1 && model.UserIds[model.UserIds.Length - 1] == ';')
model.UserIds = model.UserIds.Substring(0, model.UserIds.Length - 1);
var tags = HtmlHelperExtension.ExtractCheckListBoxResult(collection).Where(i => i.Item2).Select(i => i.Item1).ToArray();
var groups = model.ChosenGroups.Where(i => i.Checked == true).Select(i => i.Id).ToArray();
var url = String.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~/"));
SendActivityEmails(model.Name, url + "OIP/Activity/", emails);
return RedirectToAction("_Activities", "OIP");
}
型号:
public class ActivityModel
{
public long Id { get; set; }
public string ObjectId { get; set; }
public TagDTO[] Tags { get; set; }
public ModelItemChecked[] ChosenTags { get; set; }
public DateTime StartDate { get; set; }
public DateTime Deadline { get; set; }
public DateTime ResultsAnnouncement { get; set; }
}
我找不到有类似问题的人。