Is there a way to control how built-in display templates (like decimal, string) should render null fields / empty string? I'd want to show "-" as field value for some and empty line for others.
I know I can check those fields for null in the views, but this seems like a not nice thing to do in hundreds of places.
Apply the NullDisplayText property of the DisplayFormat attribute to the relevant view model members.
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "-")]
public string Name { get; set; }
Note, the DisplayFormat attribute is intended to be used with templated helpers such as EditorFor and DisplayFor (which it sounds like you are doing).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With