Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch Statement in Kendo Template

Im using Kendo Template and I was able to create a conditional statement (IF statement) as stated on the documentaion. Here's my code.

#if ((item.ControlType) == "tbx"){#
   @(Html.Kendo().AutoComplete()
   .Name("#=ctrlid#")
   .ToClientTemplate())
#}#

This works fine.

But what I'd like to have is a Switch Case Statement. I've tried this but it doesn't work. It says "Invalid Template".

# switch (item.ControlType) {#
  # case "tbx": #
     @(Html.Kendo().AutoComplete()
       .Name("#=ctrlid#")
       .ToClientTemplate())
  # break; #
  # }#

Am I missing something? Or is it just impossible for Kendo Template to interpret Switch Case Statements? (about the latter, I dont think so..I'm definitely missing something)

Can anyone help me please? Thanks!^^

like image 898
Jude Duran Avatar asked Feb 18 '13 06:02

Jude Duran


1 Answers

I check your case and I found the reason for the error. Basically to keep the JavaScript valid you will have to use only one pair of # symbols surounding the switch statement and the first case statement.

e.g.

instead of:

# switch (item.ControlType) {#
# case "tbx": #

use:

# switch (item.ControlType) {
  case "tbx": #

To demonstrate it , here is a jsbin. Basically there should not be problems if you combine the switch with some widget generated by the MVC wrappers. If there is, let me know.

like image 72
Petur Subev Avatar answered Oct 21 '22 07:10

Petur Subev