Question

I'm trying to wrap my head around the proper syntax to achieve the following--or at least to find out if it's even do-able or if there is a better alternative solution.

Ok, out of the box, when you generate a strongly-typed View using the List scaffold under ASP.Net MVC3 you get a simple table with a column that has something like two or three Html.ActionLink() items representing common actions like so: Edit | Details | Delete

I would like to use the MvcContrib grid and do the same, but I cannot figure out the correct syntax to get it to work. So far, in my Index.cshtml, I have the following snippet:

@(
        Html.Grid(Model.PagedList).AutoGenerateColumns()
            .Columns(column => 
            {
                column.For(f => Html.ActionLink("Edit", "Edit", new { id = f.itemID}))
                .Named("");
            })
            .Sort(Model.GridSortOptions);
    )

but that just gives me one column for "Edit", where as I want the column to contain three action links--Edit, Devices, Delete--with all three having the same itemID for the particular row. Is this achievable? And if so, how? If not, is there an alternative?

Was it helpful?

Solution

You could use a custom column:

columns.Custom(
    @<text>
        @Html.ActionLink("edit", "edit", new { id = item.Id }) |
        @Html.ActionLink("details", "details", new { id = item.Id }) |
        @Html.ActionLink("delete", "delete", new { id = item.Id }) |
    </text>
);

OTHER TIPS

Maybe it helps somebody:

@Html.Grid(Model).Columns(column =>
    {
        column.For( c=> Html.Raw(Html.ActionLink(...).ToString() + 
            " " + Html.ActionLink(...).ToString())).Named("Actions").Encode(false);
....

You should pass an inline helper:

column.For(@<text>
    @Html.ActionLink("Edit", "Edit", new { id = item.itemID })
    @Html.ActionLink(...)
    @Html.ActionLink(...)
</text>)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top