ASP.NET MVC, Implementing MVC-Grid With Clickable Items

573 Views Asked by At

After spending a lot of time on research, I finally found a suiting grid for my ASP.NET MVC application, it is the mvc-grid. Now, after implementing it everthing is looking fine, but I noticed that one essential function was missing, I cannot click on the items (columns). As far as I can see there is not such property to tell to one of the columns that it is clickable (or even the whole row could be clickable and change color when clicked). But I need it to be clickable in order to display the details to the selected item.

Has anybody implemented this kind of Grid and has any information on how to make the columns actual links (buttons ...) and e.g. call a javascript function

Here is the code of the grid:

@(Html
.Grid(Model)
.Build(columns =>
{
    columns.Add(model => model.Name).Titled("Name");
    columns.Add(model => model.Surname).Titled("Surname");

    columns.Add(model => model.Age).Titled("Age");   
})
.Pageable(pager =>
{
    pager.PagesToDisplay = 2;
    pager.RowsPerPage = 4;
})
.Filterable()
.Sortable()
)

Thank you

1

There are 1 best solutions below

0
user3466562 On

I have found a solution for this Grid component.I just have to add the column like this:

columns.Add().Encoded(false).Sanitized(false).RenderValueAs(o => @<a href="/INV_Locations/Edit/@o.Id" class="btn btn-success btn-sm noDecoration"><span class="glyphicon glyphicon-pencil"></span> Edit</a>).SetWidth(15);

Actually that was the first component I was using but since it does not provide Ajax Paging I had to switch (although those 2 components are pretty similar)

I tried using this method with the component I am using, but there is no such method as RenderValueAs, there is a method RenderedAsbut it does not take the same arguments and when I use it like the RenderValueAs method I get the error:

 Cannot convert lambda expression to type 'object' because it is not a delegate type

I guess there must be a way implementing a column as a link (otherwise the grid would be useless), but there is no documentation where I could look at so I hope that somebody did that already and can give me some tips

Thank you