Can I reduce this razor code?
<li>
@{
if (@Model.PublicationDate.HasValue) {
@Model.PublicationDate.Value.ToString("D", new System.Globalization.CultureInfo("fr-FR"))
}
else {
@:"pas disponible"
}
}
</li>
I was trying this but it doesn’t work:
@{(@Model.PublicationDate.HasValue) ? (@Model.PublicationDate.Value.ToString("D")) : (@:"pas disponible")}
You could decorate your view model property with the
[DisplayFormat]attribute:and then your view simply becomes:
So now it is reduced to a single and elegant line.