Search code examples
asp.net-mvclinqrazorwebgrid

ASP.NET MVC Webgrid column with actionlink, using lambda expression to get string for actionlink title?


Essentially I have a webgrid column and I want to populate it with actionlinks. The title of the actionlink needs to be dynamic and grabbed from a lambda expression. What I have is this:

grid.Column("Title", format: @<text>@Html.ActionLink("LAMDA", "Post", new { id = item.PostId }) </text>),            

But what I am trying to do is something like this:

grid.Column("Title", format: @<text>@Html.ActionLink((item) => (item).Title.ToString(), "Post", new { id = item.PostId }) </text>),            

But this gives me error:

Compiler Error Message: CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type


Solution

  • Figured it out.. for some reason you cannot use ToString(), I had to cast like (string)... weird

    solution:

    grid.Column(columnName: "Title", format: (item) => Html.ActionLink(((string)item.Title), "Post", new { id = item.PostId })),