0

I am using asp.net mvc 4 and in my page I have a list of payments:

id | status| customerid
1  | 1     | 2

code:

  <tr>
            <td>
                    @Html.DisplayFor(modelItem => item.id)
            </td>
            <td>

         @{
            var status = ((status)(modelItem => item.StatusId)).toString();
         }

            </td>
            <td>
                    @Html.DisplayFor(modelItem => item.CustomerId)
            </td>
         </tr>

I have defined an enum in my controller:

enum status { Pending = 1, Paid = 2 };

How can I display the text ie Pending instead of the id 1 on my razorpage? I am gettting an error now:

 Cannot convert lambda expression to type 'MyApp.Models.status' because it is not a delegate type
1

2 Answers 2

1

You can extend HtmlHelper (a method that will render text instead of id number) See How to extend html helper

Sign up to request clarification or add additional context in comments.

Comments

1

You need to cast in enum first as

var status=((status)(modelItem => item.StatusId)).toString();

this should give you the name of the enum.

And then you can use @Html.Label( to render it on your view rather than @Html.DisplayFor(modelItem => item.StatusId)

More details about casting enum

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.