C# IE9中的ASP MVC日期时间验证问题

C# IE9中的ASP MVC日期时间验证问题,c#,angularjs,validation,asp.net-mvc-4,datetime,C#,Angularjs,Validation,Asp.net Mvc 4,Datetime,我正在修复使用ASP.NET MVC Razor和Angular开发的应用程序上的一个错误 问题是在IE9中,datetime值根本没有显示在输入框中 我已经追踪到一个required,它不断添加required=required 模型中的IncidentDate属性为nullable datetime public System.DateTime ? IncidentDate { get; set; } 它在IE10+、FF和Chrome中运行良好,但在IE9中DateTime根本不显示

我正在修复使用ASP.NET MVC Razor和Angular开发的应用程序上的一个错误

问题是在IE9中,datetime值根本没有显示在输入框中

我已经追踪到一个required,它不断添加required=required

模型中的IncidentDate属性为nullable datetime

 public System.DateTime ? IncidentDate { get; set; }
它在IE10+、FF和Chrome中运行良好,但在IE9中DateTime根本不显示

如果编辑标记html并删除所需标记,则输入框中会显示DateTime值

我尝试在应用程序_start中添加以下行,但仍然存在相同的问题:

ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new DataAnnotationsModelValidatorProvider());
下面是在IE中生成的标记

<input name="Incident.IncidentDate" class="form-control ng-valid ng-isolate-scope input-validation-error ng-touched ng-dirty ng-valid-parse" id="Incident_IncidentDate" aria-invalid="true" aria-required="true" aria-describedby="Incident_IncidentDate-error" type="text" placeholder="dd/mm/yyyy h:mm am/pm" value="22/09/2015 2:00:00 PM" ng-model="model.Incident.IncidentDate" use-datepicker="true" format="DD/MM/YYYY hh:mm a" date-time-picker="" data-val-required="The Date and time of  incident field is required." data-val="true" use-timepicker="true" data-val-daterange-min="1753-01-01T00:00:00" data-val-daterange-max="9999-12-31T23:59:59" data-val-daterange="The field Date and time of incident is invalid.">
日期值同时出现在IE9和IE 10中,但随着日期的显示,它会带来另一个问题,如:

2015-09-22T14:00:00+10:00

修理

将编辑器模板中的格式设置为DD/MM/YYYY h:MM a


谢谢大家的建议。

您一直在使用哪个版本的angular js?因为这里是关于兼容性的链接


这里是关于您一直面临的问题的另一个链接

我通过将编辑器模板中的格式设置为DD/MM/YYYY h:MM a来修复它


谢谢大家的建议。

您使用过datepicker插件吗?@pankaj是的,我可以看到插件的参考资料您使用过哪个版本的angular js?因为这里是关于兼容性的链接。这里是关于您一直面临的问题的另一个链接@Rocky correct。。Angular1.3+不支持IE9谢谢你的建议,但在我的应用程序中,它使用的是AngularJS v1.4.2。
DateTime? value = null;
if (ViewData.Model != null)
{
    value = ViewData.Model as DateTime?;
}

bool? datePicker = ViewData["datePicker"] as Nullable<bool> ?? true;
bool? timePicker = ViewData["timePicker"] as Nullable<bool> ?? false;
bool? showFormat = ViewData["showFormat"] as Nullable<bool> ?? true;

bool? small = ViewData["small"] as Nullable<bool> ?? false;
string groupClass = small.Value ? "input-group input-group-sm" : "input-group";

IDictionary<string, object> htmlAttributes = ViewData["htmlAttributes"] == null ? new Dictionary<string, object>() : ViewData["htmlAttributes"].ToDictionary();

string inputName = htmlAttributes.ContainsKey("Name") ? htmlAttributes["Name"].ToString() : Html.NameForModel().ToString();
string ngModel; 
if (!htmlAttributes.ContainsKey("ng-model"))
{
    ngModel = "model." + inputName;
    htmlAttributes.Set("ng-model", ngModel);
}
else
{
    ngModel = htmlAttributes["ng-model"] as string;
}
htmlAttributes.Set("Name", inputName);
htmlAttributes.Set("id", Html.IdForModel());
htmlAttributes.Set("class", "form-control");
//htmlAttributes.Set("ng-init", ngModel + " = ((" + ngModel + " == '0001-01-01T00:00:00' || " + ngModel +" == '1/01/0001 12:00:00 AM') ? '' : " + ngModel + ")"); // HACK: Make DateTime.MinValue display as empty

htmlAttributes.Set("date-time-picker", string.Empty);

const string DATE_FORMAT = "DD/MM/YYYY";
const string DATE_FORMAT_HINT = "dd/mm/yyyy";
const string TIME_FORMAT = "hh:mm a";
const string TIME_FORMAT_HINT = "h:mm am/pm";

string dateTimeFormatHint;
string dateTimeFormat;
if (datePicker == true && timePicker == false)
{
    //dateTimeFormat = "d/m/Y"; // xdan
    dateTimeFormat = DATE_FORMAT;
    dateTimeFormatHint = DATE_FORMAT_HINT;
    htmlAttributes.Set("default-time", "00:00:00"); // Set default time to start of the day
}
else if (datePicker == false && timePicker == true)
{
    //dateTimeFormat = "g:i a"; // xdan
    dateTimeFormat = TIME_FORMAT;
    dateTimeFormatHint = TIME_FORMAT_HINT;
}
else
{
    dateTimeFormat = "d/m/Y g:i a"; // xdan
   // dateTimeFormat = DATE_FORMAT + " " + TIME_FORMAT;
    dateTimeFormatHint = DATE_FORMAT_HINT + " " + TIME_FORMAT_HINT;
}
htmlAttributes.Set("format", dateTimeFormat);
//htmlAttributes.Set("placeholder", dateTimeFormatHint);


if (datePicker == true)
{
    htmlAttributes.Set("use-datepicker", "true", true);
}
if (timePicker == true)
{
    htmlAttributes.Set("use-timepicker", "true", true);
}
}
<div class="datepicker">
@Html.TextBoxFor(m => m, htmlAttributes)
</div>
@if (showFormat == true)
{ 
<div class="help-block small">eg: @dateTimeFormatHint</div>
}
htmlAttributes.Set("format", dateTimeFormat);