Hyperlink not showing in grid column

6 posts, 0 answers
  1. Brad
    Brad avatar
    2 posts
    Member since:
    Oct 2014

    Posted 10 Nov 2014 Link to this post

    I have wired up a simple grid with some bound columns and one of those columns I'm trying to create a hyperlink.  Here is my code:

    @(Html.Kendo().Grid(Model.CareAlerts)
        .Name("Alerts")
        .Columns(columns =>
        {
            columns.Bound(p => p.AlertDate).Title("Date").Format("{0:d}");
            columns.Bound(p => p.PatientName).Template(@<text>
                @Html.ActionLink(@item.PatientName, "Member", new { id = @item.PatientASID })
            </text>);
            columns.Bound(p => p.AlertSummary).Title("Message");
        })
                                            .Sortable()
                                            .DataSource(dataSource => dataSource
                                                    .Ajax()
                                                    .PageSize(20)
                                                    .ServerOperation(false)
                                                 )
                )

    The second column is the column where I'm attempting to show the hyperlink.  Now, when I render the page, I can see the hyperlink for a split second before it disappears and I just see the text is supposed to be included in the link, but it is not linked after that.

    Now, here's the funny thing:  If I remove the reference to kendo.aspnetmvc.min.js in my BundleConfig.cs file, the hyperlinks show up just fine, however, I get a "Script not included" error if I do this.

    Any idea what I'm doing wrong?
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2311 posts

    Posted 12 Nov 2014 Link to this post

    Hi Brad,


    The reason for the problem is that the current Grid is using an Ajax dataSource i.e. the data is bound on the client side. This means that client templates should be used instead of server ones. You could check the following documentation page for further details.
    E.g.
    columns.Bound(p => p.ProductID).ClientTemplate(
        "<a href='" +
            Url.Action("ProductDetails", "Product") +
            "/#= ProductID #'" +
        ">Show Product Details</a>"
    );

    Regards,
    Dimiter Madjarov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Brad
    Brad avatar
    2 posts
    Member since:
    Oct 2014

    Posted 12 Nov 2014 in reply to Dimiter Madjarov Link to this post

    Dimiter,

    Thanks for the response.  I was not meaning to use ajax and was merely following an example in the documentation when I set this up.  After reading your response, I was able to fix the problem by removing the following lines of code:

    .DataSource(dataSource => dataSource
               .Ajax()
               .PageSize(20)
               .ServerOperation(false)
    )

    After removing this, everything seems to work fine.

    Thanks,

    Brad
  4. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2311 posts

    Posted 12 Nov 2014 Link to this post

    Hi Brad,


    You are correct, if an Ajax DataSource is not required, this is the correct way to resolve the problem.

    Regards,
    Dimiter Madjarov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. krishna
    krishna avatar
    4 posts
    Member since:
    Jan 2015

    Posted 30 Mar 2015 in reply to Dimiter Madjarov Link to this post

    Hi Dimiter ! How do i do it if i dont want hardcoding for "Show Product Details" part ?  I need to display the corresponding ProductID itself as the hyperlink for every new row!
  6. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2311 posts

    Posted 31 Mar 2015 Link to this post

    Hello Gopikrishna,

    In this case you could add another binding expression inside the template.
    E.g.

    columns.Bound(p => p.ProductID).ClientTemplate(
        "<a href='" +
            Url.Action("ProductDetails", "Product") +
            "/#= ProductID #'" +
        ">#= ProductID #</a>"
    );

    Regards,
    Dimiter Madjarov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top