0

I am trying to display the link based on if condition in web grid in asp.net mvc. If the record exceeds end date, then the link is displayed else not.

grid.Column("", format: (item =>
    {
        if (DateTime.Now > item.EndDate)
        {
            Html.ActionLink(
                "File ClAIM",
                "Edit",
                new { id = item.id },
                new { @class = "action-link" });
        }
        return false;
    }))

It is displaying false in all my records.Any help would be appreciated.

0

2 Answers 2

2

You need to use ternary operator following way:

grid.Column("", format: (item => { DateTime.Now > item.EndDate ? Html.ActionLink("File ClAIM", "Edit", new { id = item.id }, new { @class = "action-link" }) : String.Empty }))
Sign up to request clarification or add additional context in comments.

Comments

0

You are missing a return before Html.ActionLink(...). Since the return false is not in an else branch it is executed in either case. I added a bit of formatting to your code snippet. My point might be a bit more obvious to you this way.

By the way, false is not a string. I am slightly surprised that the code compiles, though I don't know the webgrid component in detail. You will want to return a string in the else case, too. string.Empty, null, " " - whatever you see fit.

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.