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

Using Data Values in MVC Action call from a template

1 Answer 166 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Charlie
Top achievements
Rank 1
Charlie asked on 30 Dec 2012, 11:11 PM
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>

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 01 Jan 2013, 02:29 PM
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!
Tags
Templates
Asked by
Charlie
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or