thatthing
thatthing

Reputation: 676

If condition in @Html.DisplayFor

I am trying to display different messages based on data from statusid table. Let say for example if my statusid is 1120 then i would like to display "PASS" but i am struggling with the correct syntax.

If statusid=1120 then "PASS".

Here is my code for displaying statusid:

@Html.DisplayFor(modelItem => item.statusid)

Any idea?

Upvotes: 4

Views: 10142

Answers (2)

Romeo
Romeo

Reputation: 1831

If you only have a few values from statusid then you can do this.

@if (@Model.statusid == 1120)
            {
                <span>PASS</span>
            }
            else
            {
                <span>FAIL</span>
            }

Upvotes: 5

TGH
TGH

Reputation: 39248

Make an object with all the properties you need

SomeObject.statusId
SomeObject.message

@Html.DisplayFor(modelItem => item.SomeObjectInstance)

Doing it this way let's you add the code and logic outside the view, which is generally recommended.

Upvotes: 5

Related Questions