ClientTemplate using #

2 posts, 1 answers
  1. Allan
    Allan avatar
    34 posts
    Member since:
    Aug 2015

    Posted 26 Feb Link to this post

    I want to give something a data-target value in my grid results.  I used a client template to achieve this but I cannot give the data-target an identifier, as soon as I type data-target=''#mymodal' the system crashes and the grid breaks and fails to load.  Is there anyway to include a # in my client template that won't breakt he grid?

     

    @(Html.Kendo().Grid<Kendo_Range_Test.ViewModels.VesselViewModel>()
          .Name("Grid")
          .Columns(columns =>
          {
              columns.Bound(c => c.owner_company);          
              columns.Bound(c => c.vessel_status);
              columns.Command(command => { command.Edit(); }).Width(180);
              columns.Bound(c => c.vessel_idx)
                   .ClientTemplate(
                   "<a href='" + Url.Action("Create", "Fixture") + "/#=vessel_idx #'" + ">Fixture</a>");
              columns.Bound(c => c.vessel_idx)
                   .ClientTemplate(
                   "<a data-toggle='modal' data-target='#myModal' href='" + Url.Action("Create", "Fixture") + "/#=vessel_idx #'" + ">Details</a>");
               
          }
          )
          .Editable(editable => editable.Mode(GridEditMode.InLine))
          .Pageable()
          .Reorderable(reorder => reorder.Columns(true))
          .DataSource(dataSource => dataSource
              .Ajax()
              .PageSize(40)
              .Model(model =>
                  {
                      model.Id(p => p.vessel_idx);
     
                  })
              .Read(read => read.Action("vessels_Read", "BrokerHome"))
              .Update(update => update.Action("vessels_Update", "BrokerHome"))
          )
    )

     

     

    Thanks

  2. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 26 Feb Link to this post

    Hello Allan,

    The # symbols which are not part of the template syntax should be escaped.
    E.g.

    .ClientTemplate("<a data-toggle='modal' data-target='\\#myModal'

    Regards,
    Dimiter Madjarov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top