I have a Model like so:
class Model
{
public String Text { get; set; }
public AnotherType[] Values { get; set; }
}
And a View that takes an IEnumerable<Model>
that I am displaying in a WebGrid using Razor and asp.net MVC 4.
So far I have:
@{ var grid = new WebGrid(Model); }
<div id="grid">
@grid.GetHtml(
columns:
grid.Columns(
grid.Column("Text")))
</div>
What I would like is to create a list of comma separated list of links based on the value of Values
in my model in the second column.
I have tried just creating a Linq query to project them into ActionLink
s, (or even a String Array and use String.Join() to test it) but that doesn't compile at Runtime.
For example:
grid.Column("Values",
format: (item) => String.Join(item.Select(v => v.Property).ToArray()))))
The error I get is (I think):
error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
I'd like my output to look like:
|--------------------------------| |**Text** | **Values** | |--------------------------------| |Text A | Val 1, Val 2, Val 3 | |--------------------------------|
Where Val n
is a link that can navigate you away to view more detail.
Does anyone know of a way to do this?
As a workaround, I have combined the values in my Model and expose a String
property with the result, but this doesn't allow me to create ActionLink
s.