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

Javascript call with parameter from inside a template

5 Answers 216 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Laurie
Top achievements
Rank 2
Laurie asked on 10 Apr 2015, 08:03 PM

I have the following code that I am trying to use to delete an item in the database when someone clicks the delete button:
 

<script id="treeview-template" type="text/kendo-ui-template">
         #: item.name #
         <a href="javascript:void(0)" class='btn-sm btn-danger' onclick="DeleteNode(@item.id)">x</a>
 </script>
 @Html.Kendo().TreeView().Name("Categories").ExpandAll(true).Template("treeview-template").DataSource(dataSource => dataSource
.Model(model => model
.Id("id")
         .HasChildren("hasChildren")
         )
           .Read(read => read.Action("GetCategories", "Categories"))).DataTextField("name").DragAndDrop(true).Checkboxes(true).Events(events => events.Change("onChange").Select("onSelect").Check("onCheck").Collapse("onCollapse").Expand("onExpand").DragStart("onDragStart").Drag("onDrag").Drop("onDrop").DragEnd("onDragEnd"))

The issue I'm having is that the field I'm trying to pass to the function, @item.id, is causing the exception: "The name 'item' does not exist in the current context." How can I format the code so this works?

Thanks.

Laurie

5 Answers, 1 is accepted

Sort by
0
Laurie
Top achievements
Rank 2
answered on 10 Apr 2015, 08:11 PM
Please note: I do have .TemplateId in my code rather than .Template as is in the example I gave, and it does work when I don't try to add the javascript call.
0
Laurie
Top achievements
Rank 2
answered on 13 Apr 2015, 04:05 PM
Since I haven't received a response, I'm going to post a ticket for this issue. I'll let y'all know what the upshot is.
0
Dimiter Madjarov
Telerik team
answered on 14 Apr 2015, 08:54 AM

Hello Laurie,

I covered the question in the support thread on the same topic. Let me know if the information was helpful.

Regards,
Dimiter Madjarov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Laurie
Top achievements
Rank 2
answered on 14 Apr 2015, 03:34 PM

Yes it was.  For those who are interested, the correct syntax is:

<a href='javascript:void(0)' class='btn-sm btn-danger' onclick='DeleteNode(#:item.id#)'>x</a>

Visual Studio 2013 will mark the hash marks in red, and when you hover over them will tell you it is an "Invalid character," but don't let that scare you.  It works just fine.

0
Dimiter Madjarov
Telerik team
answered on 15 Apr 2015, 10:20 AM

Hello Laurie,

Thank you for sharing the approach with the community. I am glad the issue is resolved.

Regards,
Dimiter Madjarov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
TreeView
Asked by
Laurie
Top achievements
Rank 2
Answers by
Laurie
Top achievements
Rank 2
Dimiter Madjarov
Telerik team
Share this question
or