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

Unable to add ActionLink within Grid with dynamic Labels and Links

1 Answer 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 04 Oct 2012, 08:25 PM
I would like the Bank Name within my Grid to link to the Details page based on the BankID, but I get a Compilation Error on columns.Template(@<text>:
CS1646: Keyword, identifier, or string expected after verbatim specifier: @

My .cshtml code is as follows:

@model IEnumerable<PosPayAndBankRec.Domain.Models.ORTBank>
@using Kendo.Mvc.UI.Fluent

@functions {

    private void BankGridCommandDef(GridColumnFactory<PosPayAndBankRec.Models.BankListItem> columns)
 {
  columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
        columns.Bound(p => p.BankID).Hidden();
        columns.Bound(p => p.BankName);
        columns.Bound(p => p.BankName);
        columns.Template(@<text>
                              @(Html.ActionLink("Edit", "Details", "Account", new {id = @item.BankID}))
                          </text>);
    }

    private void BankGridDataSource(DataSourceBuilder<PosPayAndBankRec.Models.BankListItem> dataSource)
 {
        dataSource.Ajax()
            .Model(AjaxBankDataSourceBuilder)
            .Sort(sort => sort.Add(p => p.BankName))
            .ServerOperation(true)
            .Create(create => create.Action("Create", "Bank"))
            .Read(read => read.Action("Read", "Bank"))
            .Update(update => update.Action("Update", "Bank"))
            .Destroy(destroy => destroy.Action("Delete", "Bank"));
            //.Events(e => e.Error("error"));
 }

    private void AjaxBankDataSourceBuilder(DataSourceModelDescriptorFactory<PosPayAndBankRec.Models.BankListItem> model)
    {
        model.Id(p => p.BankID);
        model.Field(p => p.BankName);
    }

    private void BankGridToolBarDef(GridToolBarCommandFactory<PosPayAndBankRec.Models.BankListItem> toolbar)
    {
        toolbar.Create().Text("New Bank");
    }
}

@{ ViewBag.Title = "Banks"; }
@(Html.Kendo().Grid<PosPayAndBankRec.Models.BankListItem>()
 .Name("Banks")
 .Columns(BankGridCommandDef)
 .DataSource(BankGridDataSource)
        .ToolBar(BankGridToolBarDef)
        .Editable(c => c.Mode(GridEditMode.InLine).Enabled(true).DisplayDeleteConfirmation(true))
        .Sortable()
    .Pageable(p => p.Enabled(false))
        .Scrollable(s => { s.Height(400); s.Virtual(true); })
      )
    

1 Answer, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 08 Oct 2012, 01:08 PM
I figured it out:

@{ ViewBag.Title = "Banks"; }
@(Html.Kendo().Grid<PosPayAndBankRec.Models.BankListItem>()
 .Name("Banks")
 .Columns(columns =>
            {columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
            columns.Bound(p => p.BankID).Hidden();
                columns.Bound(p => p.BankName);
            columns.Template(@<text>
   @Html.ActionLink(@item.BankName, "Details", "Account", new { id = @item.BankID }, new {bankName = @item.BankName})  
 </text>)
.ClientTemplate("<a href='/account/index/#= id#'>#=BankName#</a>")
.Title("Bank");
            })
 .DataSource(BankGridDataSource)
        .ToolBar(BankGridToolBarDef)
        .Editable(c => c.Mode(GridEditMode.InLine).Enabled(true).DisplayDeleteConfirmation(true))
        .Sortable()
    .Pageable(p => p.Enabled(false))
        .Scrollable(s => { s.Height(400); s.Virtual(true);})
      ))
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Share this question
or