If the condition is in @ Html.DisplayFor

I am trying to display different messages based on data from the status table. Say, for example, if my statusid is 1120, then I would like to display "PASS", but I'm afraid with the correct syntax.

If statusid = 1120, then "PASS".

Here is my code to display the status:

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

Any idea?

+4
source share
2 answers

Create an object with all the necessary properties.

SomeObject.statusId
SomeObject.message

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

By doing this, you can add code and logic outside the view, which is usually recommended.

+5
source

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

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

Source: https://habr.com/ru/post/1542081/


All Articles