我不知道为什么我会在Object reference not set to an instance of an object
上获得@request.StartDateDisplay
:
StartDateTime在某些请求中为空,它应返回""在StartDateDisplay为null时,或者我错过了什么?
模型变换
public class ModelView {
...
public DateTime? StartDateTime {get; set;}
public string StartDateDisplay => "Start Date " + StartDateTime?.ToShortDateString() ?? "");
...
}
查看
....
<tbody>
@foreach(var request in requests)
{
<tr>
....
<td>
@request.StartDateDisplay
</td>
....
</tr>
}
</tbody>
...