The ...For
extension methods on the HtmlHelper (e.g., DisplayFor
, TextBoxFor
, ElementFor
, etc...) take a property and nothing else. If you don't have a property, use the non-For
method (e.g., Display
, TextBox
, Element
, etc...).
The ...For
extension methods provides a way of simplifying postback by naming the control after the property. This is why it takes an expression and not simply a value. If you are not interested in this postback facilitation then do not use the ...For
methods at all.
Note: You should not be doing things like calling ToString
inside the view. This should be done inside the view model. I realize that a lot of demo projects put domain objects straight into the view. In my experience, this rarely works because it assumes that you do not want any formatting on the data in the domain entity. Best practice is to create a view model that wraps the entity into something that can be directly consumed by the view. Most of the properties in this view model should be strings that are already formatted or data for which you have element or display templates created.