FrostyStraw
FrostyStraw

Reputation: 1656

ActionLink inside an if statement inside a webgrid

I have a webgrid that I am making, and I want one of the columns to display a download link to a file on the server if there is one, and the words "no file uploaded" if there is not. I tried to do something like this, but then I get an error that says:

Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

 grid.Column( header: "File", format: @<span>
           @if (item.personfile != null) { 
         (item) => (@Html.ActionLink("Download file", "downloadFile", "Person", new { id = item.id }, null))
           }

I need to use the actionlink but I don't know how to incorporate it with the rest of the html. I haven't bothered making an else condition yet because this piece of code doesn't seem to work at all

Upvotes: 0

Views: 358

Answers (1)

ramiramilu
ramiramilu

Reputation: 17182

Try below code. Here is the working sample - https://dotnetfiddle.net/tjl1Ka

grid.Column( header: "File",
     format:(item) => (item.personfile != null)
     ? Html.ActionLink("Download file", "downloadFile", "Person", new { id = item.id })
     : Html.Raw("No File Found"))

Upvotes: 1

Related Questions