Using Data Values in MVC Action call from a template

2 posts, 0 answers
  1. Charlie
    Charlie avatar
    1 posts
    Member since:
    Dec 2012

    Posted 30 Dec 2012 Link to this post

    I am wondering if this can be done as I have not seen a specific example.  What I would like to do is this:

    <script type="text/x-kendo-template" id="template">
        <div id="details-container">
            <h2>#= EnterpriseImageFileName #</h2>
            <img src='@Url.Action("RenderImage", "Member", new { enterpriseImageID = #=EnterpriseImageID# }, @Request.Url.Scheme)'/>
    <script type="text/javascript">
        var detailsTemplate = kendo.template($("#template").html());
        function showDetails(e) {
            var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
            var wnd = $("#Details").data("kendoWindow");
    However, the template value can't referenced from the Razor syntax.  Is there a way to gracefully, get the value of #=EnterpriseImageID# and use it in the call to to Action?

    As an FYI - this works but I would like to use the Action helper method if possible:

    <script type="text/x-kendo-template" id="template">
        <div id="details-container">
            <h2>#= EnterpriseImageFileName #</h2>
            <img src='../RenderImage/?enterpriseImageID=#=EnterpriseImageID#' />
  2. Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 01 Jan 2013 Link to this post


    When using the MVC helper the  sharp symbols #= #  are encoded and they are no longer able to be evaluated. You can mix the URL helper and attach the expression result manually to the query string.

    <a href="' + '@Url.Action("Foo", "Bar")' + '&imageID=' + data.imageID+ '">

    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top