Because DisplayFor does not render an input field for the property. That's why it's called DisplayFor, and not EditorFor. It's meant to be used to display the property to the user.
As an example, let's say you have a string property called Name with the value of "John" in your Model. In that case, here is how Html.EditorFor
and Html.DisplayFor
are rendered for that property on the page:
@Html.EditorFor(model => model.Name)
This will be rendered as:
<input name="Name" id="Name" type="text" value="John" />
But,
@Html.DisplayFor(model => model.Name)
will be rendered as:
John
By the way, Html.HiddenFor
will render a hidden field on your page which will be posted to your Controller. With the above example,
@Html.HiddenFor(model => model.Name)
will be rendered like this:
<input name="Name" id="Name" type="hidden" value="John" />
You use EditorFor
when you want the user to enter data into your page, use DisplayFor
when you want to display a read-only data to the user, and use HiddenFor
when you want to post the data to the Controller when the form is submitted, but the data is not supposed to be edited by and visible to the user. An example is an ID field that's not edited by the user, but you need it in your form.
Have a look at this post: What is the @Html.DisplayFor syntax for?