【发布时间】:2016-01-28 13:53:27
【问题描述】:
我正在使用下面的 Ajax 表单来选择和发布日期范围。
查看模型:
public class ViewFormSubmissionsVM
{
public string FormName { get; set; }
public Guid FormId { get; set; }
[Display(Name="From:")]
public DateTime From { get; set; }
[Display(Name = "To:")]
public DateTime To { get; set; }
}
剃刀/HTML:
@model ViewFormSubmissionsVM
@using (Ajax.BeginForm("ViewFormSubmissions", "Form", new AjaxOptions { HttpMethod = "POST", OnSuccess = "onGetSubmissionSuccess", OnFailure = "onGetSubmissionError" }, new { @class = "form-horizontal" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(x => x.FormId)
<div class="row col-md-12">
<div class="pull-right">
<label class="control-label col-md-3">@Html.DisplayNameFor(x => x.From)</label>
@Html.TextBoxFor(x => x.From, "{0:MM/dd/yyyy}", new { @class = "form-control col-md-3", @data_picker = "date-picker" })
<label class="col-md-3">@Html.DisplayNameFor(x => x.To)</label>
@Html.TextBoxFor(x => x.To, "{0:MM/dd/yyyy}", new { @class = "form-control col-md-3", @data_picker = "date-picker" })
<input type="submit" class="btn btn-primary" value="Search" />
</div>
</div>
}
JQuery 日期选择器:
$(document).ready(function () {
$('*[data-picker="date-picker"]').datepicker();
});
此问题是在提交表单时,“From”和“To”Datetime 属性接收到默认日期值而不是选中。
我错过了什么重要的东西吗?我已经以不同的形式使用过这些代码,但以前从未体验过。
谁能帮我摆脱这个问题。
非常感谢。
【问题讨论】:
-
模型日期是空白还是您为它们设置了值?
-
有值,返回 View(new ViewFormSubmissionsVM { FormId = id, From = DateTime.Now.AddMonths(-1), To = DateTime.Now });
-
服务器的文化是什么?它是不变的还是接受
DateTime格式的MM/dd/yyyy?
标签: asp.net-mvc jquery-ui datetime datepicker ajax.beginform