0

I have my column bind on the grid as follows:

columns.Bound(p => p.LastName)
     .ClientTemplate($"#=IsSpecialPerson ? 'Special Message' : ''##=LastName#")

And now I have to add middle name with a space to the last name column if exists. I have tried the following, but no luck.

columns.Bound(p => p.LastName)
   .ClientTemplate($"#=IsSpecialPerson ? 'Special Message' : ''##=LastName# ##= MiddleName != null ? MiddleName : ''#") 

I am getting invalid template error on the html.

James Z
  • 12,209
  • 10
  • 24
  • 44
Tiger
  • 417
  • 2
  • 8
  • 23

1 Answers1

2

A quick way to check your template is to count the number of #'s. It should be an even number. If I write your template over separate lines it is easier to see where the problem is:

#=IsSpecialPerson ? 'Special Message' : ''#
#=LastName#
##= MiddleName != null ? MiddleName : ''#  // You have 3 #'s here

May I suggest this:

#=IsSpecialPerson ? 'Special Message' : ''#
#=LastName#
#if (data.MiddleName != null) {#  // I forget if the data prefix is needed here or not
     
    #=MiddleName#
#}#

Put that all into one line and it should give you the result you are looking for.

NigelK
  • 8,255
  • 2
  • 30
  • 28