@Html.Display()
is used instead of @Html.DisplayFor()
when your model is not known at compile time, or if you prefer to work with strings, rather than with strong types. For example, these 2 are equivalents (given that your model is some class):
@Html.DisplayFor(m => m.MyProperty)
and
@Html.Display("MyProperty")
But the additional cool feature of the Display() method is that it can also do the lookup in the ViewData, and not just in your Model class. For example, here is a way to display the HTML for the property on a random object, given that we know it has a property named "Blah" (the type of the object doesn't really matter):
@{ ViewData["itsawonderfullife"] = SomeObject; }
<div>@Html.Display("itsawonderfullife.Blah")</div>
This way, we are telling HtmlHelper
to look into the ViewData
, instead of our Model
, and to display the property Blah
of a given SomeObject
.