2
votes

In Telerik MVC 3.0 Grid (Razor engine)

How can i access the data after grid binding. I am using Detailed view tab using below code.

items.Add()
     .Text("Additional Tab")
     .Content(@<text>
    @(Html.Telerik()
          .Grid<Models.PModel>()
          .Name( "Additional_<#= AddressID #>" )
          .DataBinding( dataBinding => dataBinding.Ajax()
                                                  .Select( "Action", "Controller", new { ID = "<#= ID #>" } ) )
          .Pageable()
          .Sortable()
          .Columns( columns =>
          {
            columns.Bound( e => e.Name ).Title( "Name" ).Width( 150 );
            columns.Bound( e => e.Email ).Title( "Email" );
            columns.Bound( e => e.Status ).Title( "Prescriber Status" );
            columns.Template( e => e.ID ).ClientTemplate( 
                        Ajax.ActionLink( "Edit", "EditDetails", new { ID = "<#= ID #>", PID = "<#= PID #>" }, 
                        new AjaxOptions
                        {
                            OnSuccess = "LoadAddEditForm",
                            UpdateTargetId = "ShowAddEditFormDialogModel",
                            InsertionMode = InsertionMode.Replace
                        },
                        new { @class = "button" } ).ToString() );
          } )
         .NoRecordsTemplate( "No additional added for this" )
    )
@Ajax.ActionLink("Add New", "AddEdit", "Controller", 
    new { ID =  "<#= ID #>"},
    new AjaxOptions
    {
        OnSuccess = "LoadAddEditForm",
        UpdateTargetId = "ShowAddEditFormDialogModel",
        InsertionMode = InsertionMode.Replace
    }, 
    new { @class = "button", id="AjaxAddNewButton" })
</text>);

Now the Problem is,, if you notice i have added a Ajax.Action link after the grid binding.

@Ajax.ActionLink("Add New", "AddEdit", "Controller", 
    new { ID =  "<#= ID #>"},
    new AjaxOptions
    {
        OnSuccess = "LoadAddEditForm",
        UpdateTargetId = "ShowAddEditFormDialogModel",
        InsertionMode = InsertionMode.Replace
    },
    new { @class = "button", id="AjaxAddNewButton" })

In this Ajax Link I can get the value of object new { ID = "<#= ID #>"} as I am trying to access the <#= ID #> after the grid binding, it is not rendering the value. How can i get this work?

Any help would be greatly appreciated.

Thanks

1
I would be interested in the answer to this question, though I don't think what you're asking is possible. Since the Ajax.ActionLink is created on the server, it can't be updated on the client with server-side code. You'd have to update the link on the client in Javascript. Or maybe there is some way to bind the route value using MVC..? - ken
Well we can do this in clinetTemplate. when row is binding, we can assign object values with <#= filedName #>, Only question is how can we do it after grid binding is complete. There is other alternate .toolbar(c=>c.custom().text("Add").Action("action","Controller",new{ID="<#= ID #>"})) But even in this way <#= ID #> doesn't render the value - HaBo

1 Answers

0
votes

This is not possible.

The <# ID #> you are using is for a single row in your grid. It cannot be used outside the .Columns() method. So your column template may work, but if you inspect what is being sent to the Action handling the binding, you will see that the ID parameter literally equals "<# ID #>".

For the ActionLink past the grid, what ID did you want? from which row?