我的ASP.NET核心表单存在问题,它包括从同一表单提交两个日期时间值。我有一个像这样的句号对象:
public class PricePeriod
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set;}
}
然后是剃刀html:
<form class="form-horizontal" id="editNewPeriod" asp-action="SavePeriod" asp-controller="Administration" data-ajax="true" data-ajax-method="POST" data-ajax-mode="REPLACE-WITH" data-ajax-update="#newPeriodDialog">
<label>Id: </label> <input type="text" id="PeriodId" name="PeriodId" value="@Model.Id" style="color:grey;" readonly></br>
<label>Navn: </label> <input type="text" placeholder="@Model.NamePlaceHolder" value="@Model.Name" name="Name" /></br>
<label for="PeriodStart">Fra: </label> <input value="@Model.StartDate" asp-for="PeriodStart" class="datepicker" />
<label for="PeriodEnd"> Til: </label><input asp-for="PeriodEnd" value="@Model.EndDate" class="datepicker" /></br>
<input type="submit" value="Gem" class="btn btn-primary"/>
<button type="button" class="btn btn-default" data-dismiss="modal">Luk</button>
</form>
<script type="text/javascript">
//Functions to control range-picking
$(function(){
initializeDatepickers();
});
function initializeDatepickers(){
var dateFormat = "dd/mm/yy",
from = $("#PeriodStart")
.datepicker({
dateFormat: dateFormat,
showWeek: true,
firstDay: 1,
changeMonth: true,
changeYear: true,
showOtherMonths: true,
selectOtherMonths: true,
showAnim: "blind"
})
.on( "change", function() {
to.datepicker("option", "minDate", getDate(this));
}),
to = $("#PeriodEnd")
.datepicker({
dateFormat: dateFormat,
showWeek: true,
firstDay: 1,
changeMonth: true,
changeYear: true,
showOtherMonths: true,
selectOtherMonths: true,
showAnim: "blind"
})
.on( "change", function() {
from.datepicker( "option", "maxDate", getDate( this ) );
});
function getDate( element ) {
var date;
try {
date = $.datepicker.parseDate( dateFormat, element.value );
} catch( error ) {
date = null;
}
return date;
}
}
现在,这里的一切似乎都有效,除了当我提交时,提交时对象的PeriodEnd,它与DateTime.MinValue相同,我似乎无法弄清楚这里出了什么问题。我试着通过自己写出PeriodEnd的输入标签的所有属性来做HTML,但这并没有改变一件事。
感谢您的时间。