Need help with template column

5 posts, 1 answers
  1. James
    James avatar
    4 posts
    Member since:
    Oct 2012

    Posted 16 Oct 2012 Link to this post

    HI all,

    I'm a bit new to Kendo, so forgive me if this is an easy question;

    I have a grid of orders. The last column of the grid needs to be a link/button/whatever that launches a bit of JavaScript that does some AJAX stuff. Pretty simple. I found that documentation on the columns.Template method and I _think_ that's what I want. The problem is that I have only found examples where one field from the model is being used in the method call and I need three;
    columns.Template(p =>
    {@<a href="#"
    onclick="GetListOfVendorsByCountyAndProductType('@p.County', '@p.ProductTypeId.ToString()', '@p.OrderId');">Select Vendor</a>;       
                                              });
     I tried the snippet above but I got an error on the page that said "CS0201: Only assignment, call, increment, decrement, await and new object expressions can be used as a statement"

    Any advice? Please remember I'm VERY new to the Kendo stuff.

    Thanks,
    James
  2. Answer
    Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 19 Oct 2012 Link to this post

    Hello James,

    You can use the following syntax:

    columns.Template(
        @<text>
            foo
            @item.ProductName
            @item.UnitPrice
            bar
        </text>
    );

    Note that is is a server template which works with server binding. If you are using Ajax binding, you need a ClientTemplate, as explained in the Grid configuration help article.

    Regards,
    Dimo
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. James
    James avatar
    4 posts
    Member since:
    Oct 2012

    Posted 19 Oct 2012 Link to this post

    Thanks Dimo, that worked!
  5. Hassan
    Hassan avatar
    10 posts
    Member since:
    Oct 2010

    Posted 09 Nov 2012 Link to this post

    I get

    CS0103: The name 'p' does not exist in the current context

    when I try the proposed solution for AJAX binding. 

        @(Html.Kendo().Grid(Model)   
            .Name("products")
            .Columns(columns => {
                columns.Bound(p => p.Id).Visible(false);
                columns.Bound(p => p.Title).Width(280);
                columns.Bound(p => p.Brand).Width(70);           
                columns.Bound(p => p.SellPrice).Width(40);
                columns.Bound(p => p.PacketWeight).Width(60);
                columns.Bound(p => p.Enabled).Width(30);   
                columns.Template(@<text>
                @Html.ActionLink("Edit", "Home", new { id = p.Id })
           </text>);

            })
            .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model => model.Id(p => p.Id))
            .Read(read => read.Action("GetProducts", "Product").Data("additionalData"))
            )
            .Pageable()
            .Sortable()
            .Navigatable()
            .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
        )

     

     

     

     

  6. Rich Coleman
    Rich Coleman avatar
    19 posts
    Member since:
    Jan 2008

    Posted 31 Jan 2013 Link to this post

    Hassan,

    It should be

     columns.Template(@<text>
                @Html.ActionLink("Edit", "Home", new { id = item.Id })
           </text>);
Back to Top
UI for ASP.NET MVC is VS 2017 Ready