This is a migrated thread and some comments may be shown as answers.

Grid command button template column: Need syntax for referencing property of current grid row in ActionLink method using multiple properties

2 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 21 Jan 2014, 04:21 PM
I'm re-posting this as a separate issue from the one I've been working on with Petur.  I have a kendo grid, actually a sub-grid, for which I've defined a command button.  In the button I need to use a property from the master grid, which is no problem, and a property from the current row of the sub-grid where the button will be clicked.  The syntax for this is not working out, and I have not been able to find an example either of multiple parameters, nor of using a property of the current row in such a manner.  I get an error that the current row property is not defined when the page renders.  I need to sent both properties to the controller which will redirect to the proper CRUD view.  I've tried two different syntaxes.  Code is shown below.  The first example will render but lacks the critical second property.  Petur has a sample project from me that these buttons could be dropped into for you to see the problem.  The project is called TriLevel PolymorphicGridTest.

@model IEnumerable<kendoBatchHeaderTest.Models.BatchHeader>
 
@{
    ViewBag.Title = "Transaction Review";
}
 
<h2>Batches to Review/Post</h2>
 
@(Html.Kendo().Grid(Model)
    .Name("BatchGrid")
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:700px" })
    .Columns(columns =>
                {
                    columns.Bound(b => b.BatchID)
                                        .Width("100")
                                        .Title("Batch ID");
                    columns.Bound(b => b.Created_DTTM)
                                        .Width("175")
                                        .Format("{0:MM/dd/yyyy hh:mm tt}")
                                        .Title("Created");
                    columns.Bound(b => b.PostingStatus)
                                        .Width("175")
                                        .Title("Status");
                }
            )
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(40)
        .Read(read => read.Action("FetchBatchCollection", "Home"))
    )
    .ClientDetailTemplateId("transactions")
    //.Events(events => events.DataBound("dataBound"))
)
 
<!-- Nested grid for transaction object, member of BatchHeader.TranCollection
     There can be many ITransaction objects per BatchHeader -->
<script id="transactions" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<kendoBatchHeaderTest.Models.Transaction>()
            .Name("TranGrid_#=BatchID#")  // makes the sub-grid name unique so that it will be displayed on each child row.
            //.Pageable()
            .Sortable()
            .Scrollable()
            .HtmlAttributes(new { style = "height:175px; width:800px" })
            .Columns(columns =>
                {
                    columns.Template(@<text></text>)
                                       .ClientTemplate("<a href='" +
                                       Url.Action("Edit", "Home") +
                                       "/#=BatchID#'>Edit</a>")
                                       .Width("100px");
                    columns.Template(@<text>@Html.ActionLink("View Details", "Edit", "Home",
                                        new { BatchID = "#=BatchID#", TransactionID =  "=#TransactionID#" }, null)</text>)
                                        .Width("100px")
                                        .ClientTemplate("<a href='/Edit/Home/#=BatchID#/=#TransactionID#</a>");
                    columns.Bound(b => b.TransactionID)
                                        .Width("100")
                                        .Title("Transaction ID");
                    columns.Bound(b => b.TranactionType)
                                        .Width("200")
                                        .Title("Type");
                    columns.Bound(b => b.PostingMessage)
                                       .Width("600")
                                       .Title("Posting Message");
                }
                    )
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .PageSize(5)
                        .Read(read => read.Action("FetchTransactionCollection", "Home", new { batchID = "#=BatchID#" }))
                    )
            //.ClientDetailTemplateId("detailTransactions")
            //.Events(events => events.DataBound("dataBound"))
                    .ToClientTemplate()
            )

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 23 Jan 2014, 04:36 PM
Hello Richard,

The "#" characters needs to be escaped when used in a nested template in order to be evaluated in the correct context:
.ClientTemplate("<a href='" +
           Url.Action("Edit", "Home") +
           "/\\#=TransactionID\\#'>Edit</a>")


Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Richard
Top achievements
Rank 1
answered on 31 Jan 2014, 01:30 AM
Thanks, Daniel! Sorry for the late reply.  I did see this and fixed my code several days ago but forgot to reply.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Richard
Top achievements
Rank 1
Share this question
or