-1
我相信问题已经被问到,但答案不同于我的问题。如何解决System.FormatException发生在mscorlib.dll中,但没有在用户代码中处理
我有一个网格,我从中选择用户。当我点击相应的ID它适用于一些用户精细和一些它打破,并显示以下错误,
错误:
An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code
Additional information: String was not recognized as a valid DateTime.
我的编码
<div class="col-md-10">
<input type="text" value='@DateTime.Parse(Model.IncidentDate.ToString()).ToString("dd/mm/yyyy"))' class="form-control input-xs" disabled />
</div>
型号
public string PNumber { get; set; }
public DateTime? IncidentDate { get; set; }
public string CNumber { get; set; }
先进的感谢..
因为你转换'DateTime'为'字符串“,然后使用格式再次将生成的”字符串“转换为”字符串“。 - 它只是'Model.IncidentDate.ToString(“dd/mm/yyyy”)'但你认为这一点 - 你想达到什么目的? –
您的IncidentDate属性可以为空。当IncidentDate的值为空时,是否抛出异常? – MarcoLaser
@StephenMuecke我想用这种格式的日期。我只是不知道我可以如何工作。 – Mpho