Search code examples
asp.net-mvcasp.net-mvc-2html-helper

What is the difference between Html.Label and Html.Display?


What is the difference between Html.Label and Html.Display?


Solution

  • Html.Label() renders HTML markup <label /> that can be used for a model entity's attrubute.

    For eg,

    <%= Html.Label("Full Name", Model.FullName) %>
    

    would render

     <label for="FullName">Full Name </label>
    

    Html.Display() on the other hand renders HTML markup for entire entity based on specified templates. For eg. if you have a Person entity with multiple attributes, you define a template with markup as to how to render a Person and Html.Display() uses that template to render Person objects across views. Phil Haack has an excellent post on display templates.