user1307149
user1307149

Reputation: 1415

Templates can be used only for field access

This Line of Code is causing the below error.

Code:

@Html.LabelFor(y => y.Data.Select(z => z.Name).First().ToString());

Error:

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

This is in a Razor MVC4 View.

Can this be re-written or can I not do it?

Upvotes: 0

Views: 4842

Answers (1)

KeyboardFriendly
KeyboardFriendly

Reputation: 1798

Try:

Html.DisplayFor(y => y.Data.Select(z => z.Name).First().ToString())

That Will Show The Value Instead of the property name.

Upvotes: 1

Related Questions