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

Build url.action within listview template

4 Answers 768 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Leroy
Top achievements
Rank 1
Leroy asked on 02 Jun 2013, 09:07 PM
Hello,

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#  })">
        <h3>#:description#</h3>
        <p></p>
    </div>
</script>

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.

4 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 05 Jun 2013, 07:11 AM
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:

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/faq#how-do-i-use-action-links?


Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
TroyR
Top achievements
Rank 1
answered on 20 Jul 2016, 05:55 PM

Peter,

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 -->
    <div>#=MemberId#</div>

    <!-- 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>

</script>


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!

 

0
Daniel
Telerik team
answered on 25 Jul 2016, 06:40 AM
Hello,

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.

Regards,
Daniel
Telerik by Progress
 
Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
 
0
TroyR
Top achievements
Rank 1
answered on 25 Jul 2016, 01:46 PM
Thank you very much, Daniel.
Tags
ListView
Asked by
Leroy
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
TroyR
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or