我正在使用ASP.NET MVC 4和bootstrap-datepicker。我正在尝试将日期格式设为dd-mm-yyyy
。
我的模特:
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime? DataInicio_P_C { get; set; }
查看(输入和ValidationMessageFor):
<div class="input-append date" id="datepicker1" data-date="dateValue: Customer.DateOfBirth" data-date-format="dd-mm-yyyy">
@Html.TextBoxFor(model => model.DataAssin_C, new { @class = "form-control input-sm add-on", id = "DataAssin_C" })
</div>
<td colspan="2">@Html.ValidationMessageFor(model => model.DataAssin_C, "", new { @class = "error-input" })</td>
调用datepicker:
$('#datepicker').datepicker({ format: 'dd-mm-yyyy' });
但是每当我收到错误“字段DataAssin_C必须是日期”时,只需要格式mm-dd-yyyy或mm / dd / yyyy验证日期,当我想要dd-mm-yyyy
答案 0 :(得分:0)
控制器:
if (DateTime.Parse(form["DataAssin_C2"]) != null)
{
dados.DataAssin_C = DateTime.Parse(form["DataAssin_C2"]);
dados.DataAssin_C = DateTime.Parse(dados.DataAssin_C.Value.ToString("yyyy-MM-dd"));
}