1

I've got a model like this:

public class HomeViewModel
{
    public IEnumerable<NewsItem> NewsItems { get; set; }
    public decimal TotalSales { get; set; }
    public IEnumerable<SalesOrderHeader> SalesInformation { get; set; }

}

And in the View I want to do this:

<p>@Html.Display(Model.TotalSales)</p>

But I'm running into this error:

HomeViewModel does not contain a definition for Display"

Which is odd because it should be the Html type that has Display.

What is the correct syntax for what I'm trying to achieve?

1
  • you should use @Html.DisplayFor Commented Jun 8, 2015 at 16:55

2 Answers 2

4

It's better to use DisplayFor (Display) fo doing this. If you need to add some display attributes (like only last 2 digits to be shown) you will do this only one time in the ViewModel.

<p>@Html.DisplayFor(model => model.TotalSales)</p>

If you really want to use Display, the MVC is smart enough to render this with your data from Model.

<p>@Html.Display("TotalSales")</p>
Sign up to request clarification or add additional context in comments.

Comments

0

Okay it's actually:

<p>@Model.TotalSales</p>

Solved!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.