Consider the following model:
public class MyModel { public string Name { get; set; } [DisplayFormat(NullDisplayText = "No value available!")] public string Email { get; set; } }
in my opinion:
<%= Html.DisplayTextFor(m => m.Email) %> <%: Model.Email %>
The first line will display βNo Valueβ if we leave the message βnullβ and the second line will not display anything.
Conclusion: Html.DisplayTextFor considers DataAnnotations for your properties, <%: Model.Email %> will not. In addition, <%: Model.Email %> will cause an "object reference error" when the value is null, but <%= Html.DisplayTextFor %> will not.
Yngve B-Nilsen Aug 13 '10 at 10:30 2010-08-13 10:30
source share