How to GridMVC click on a row linking to details url in ASP.NET4

Nov 12, 2013 at 5:27 PM
I am trying to link the click on a grid row to showing a details view for a row, however when I trigger the function I get "The name 'e' does not exist in the current context". for the line

window.location.href = '@Url.Action("Details", "Details", new { id=e.row.ID })';

Please can you tell me what am I misunderstanding?

@Html.Grid(Model).Named("customersGrid").Columns(columns =>
                        columns.Add(foo => foo.ID, true).Titled("ID");
                        columns.Add(foo => foo.Name).Titled("Name").SetWidth(300).Sortable(true).Filterable(true);
                        columns.Add(foo => foo.AccountCode).Titled("Account Code").SetWidth(150).Sortable(true).Filterable(true);
                        columns.Add(foo => foo.Supplier).Titled("Supplier").SetWidth(300).Sortable(true).Filterable(true);
<script type="text/javascript" > $(function () { pageGrids.customersGrid.onRowSelect(function (e) { window.location.href = '@Url.Action("Details", "Details", new { id=e.row.ID })'; }); }); </script>
Nov 13, 2013 at 2:24 AM
Hi you can't combine server side @Url.Action method with client side 'e' argument...

You can pass and url address to controller action to client variable and use them to contruct full url, like
var detailsUrl = '@Url.Action("Details", "Details")';
$(function () { pageGrids.customersGrid.onRowSelect(function (e) { window.location.href = detailsUrl  + '/' + e.row.ID '; }); });
Nov 13, 2013 at 10:32 AM
Thank you Bukharin, I did finally realise my mistake before seeing your post and fixed it by using an alternative method, this allows for syntax changing.

window.location.href = '@Url.Action("Details", "Customer", new { id = "id" })'.replace('id', e.row.ID);
Oct 16, 2014 at 9:04 PM
How do you keep the selected row highlighted after details are shown?