Build url.action within listview template

5 posts, 0 answers
  1. Leroy
    Leroy avatar
    3 posts
    Member since:
    May 2013

    Posted 02 Jun 2013 Link to this post


    I'm trying to create a listview template with the following syntax:

    <script type="text/x-kendo-tmpl" id="template">
        <div class="item">
            <img src="@Url.Content("~/Content/scans/")#:thumbLocation#" alt="#:description# image" />
            <a href="@Url.Action("Index", "Controller", new { id= #: itemId#  })">

    I keep getting the error: 
    Preprocessor directives must appear as the first non-whitespace character on a line.

    How do I pass the parameter to the url action??

    Your help would be much appreciated.
  2. Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 05 Jun 2013 Link to this post

    Hello Leroy,

    The sharp symbols are automatically encoded by the Html.Action helper and thus the final output is not actually evaluated. To avoid this you need to manually append the client expression part to the URL like shown in this part of the documentation:

    Kind Regards,
    Petur Subev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. TroyR
    TroyR avatar
    7 posts
    Member since:
    Nov 2015

    Posted 20 Jul 2016 in reply to Petur Subev Link to this post


    Thank God that I've found this thread!  It's a very specific case.
    I'm trying to do something very similar to the OP.

    I'm using an MVC UI Grid with child detail templates like the one, below.  I've simplified it demonstrate my issue.  I can reference MemberId easily enough in the first set of <div> tags.  But, my grasp of C#, Razor, and/or programming is failing me for figuring out how to use MemberId in an Html.Action() method.  Is it even possible?

    <script type="text/kendo-tmpl" id="memberContributions" >
        <!-- this works -->

        <!-- these do not work -->
        <div>@{Html.Action("GetContributionForm", new { memberId = #=MemberId# }); }</div>
    <div>@{Html.Action("GetContributionForm", new { memberId = "#=MemberId#" }); }</div>
    <div>@{Html.Action("GetContributionForm", new { memberId = "\\#=MemberId\\#" }); }</div>

        <!-- this works -->
        <div>@Html.Kendo().Grid<Contribution>()... </div>


    In Leroy's case, above, you advised him not to use such a property in an Url.Action() method.
    I would really appreciate a good explanation for why this isn't working, so that I can quit trying to accomplish things in senseless ways.


    Thank you!


  4. Daniel
    Daniel avatar
    2231 posts

    Posted 25 Jul 2016 Link to this post


    Using the Action helper with the actual value is not possible. The template expression is evaluated on the client and the Action helper is executed on the server. If you do not need to the value on the server for some operation then you could use a Partial view with the template expression(s) included in the markup. If the value is required on the server then the only option that I can suggest is to load the content via Ajax in the detailInit event.

    Telerik by Progress
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
  5. TroyR
    TroyR avatar
    7 posts
    Member since:
    Nov 2015

    Posted 25 Jul 2016 in reply to Daniel Link to this post

    Thank you very much, Daniel.
Back to Top