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>
            <h2>#=EnterpriseImageID#</h2>
            <img src='@Url.Action("RenderImage", "Member", new { enterpriseImageID = #=EnterpriseImageID# }, @Request.Url.Scheme)'/>
        </div>
    </script>
     
    <script type="text/javascript">
        var detailsTemplate = kendo.template($("#template").html());
     
        function showDetails(e) {
            e.preventDefault();
                     
            var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
            var wnd = $("#Details").data("kendoWindow");
     
            wnd.content(detailsTemplate(dataItem));
            wnd.center().open();
        }
    </script>
    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>
            <h2>#=EnterpriseImageID#</h2>
            <img src='../RenderImage/?enterpriseImageID=#=EnterpriseImageID#' />
        </div>
    </script>
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 01 Jan 2013 Link to this post

    Hello,

    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.

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



    Greetings,
    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!
  3. Kendo UI is VS 2017 Ready
Back to Top