If value is null put an empty string on razor template?
This is exactly what the NullDisplayText
property on [DisplayFormat]
attribute is for.
Add this directly on your model:
[DisplayFormat(NullDisplayText="", ApplyFormatInEditMode=true)]
public string EMail { get; set; }
To Check some property of a model in cshtml.
@if(!string.IsNullOrEmpty(Model.CUSTOM_PROPERTY))
{
<p>@Model.CUSTOM_PROPERTY</p>
}
else
{
<p> - </p>
}
so best way to do this:
@(Model.CUSTOM_PROPERTY ?? "-")
If sounds like you just want:
@(UIManager.Member == null ? "" : UIManager.Member.Email)
Note the locations of the brackets is critical; with razor, @(....)
defines an explicit range to the code - hence anything outside the brackets is treated as markup (not code).