Nested grid error after deployment

3 posts, 0 answers
  1. Harper
    Harper avatar
    12 posts
    Member since:
    Oct 2013

    Posted 22 Jul 2015 Link to this post

    I have the following code: 

    @(Html.Kendo().Grid<CheckinViewModel>()
          .Name("grid_#=SubmissionLineItemId#")
          .Columns(cols =>
              {
                  cols.Command(cmd => cmd.Destroy()).Width(100);
                  cols.Bound(ci => ci.Id).Hidden();
                  cols.ForeignKey(ci => ci.StorageAreaId, (IEnumerable)ViewData["storageAreas"], "Id", "Name").Title("Storage Area");
                  cols.Bound(ci => ci.Quantity);
                  cols.Bound(ci => ci.Bags);
                  cols.Bound(ci => ci.Buckets);
                  cols.Bound(ci => ci.Jars);
              })
              .ToolBar(tb =>
              {
                  tb.Create().Text("Add Checkin");
                  tb.Save();
              })
          .Editable(ed => ed.Mode(GridEditMode.InCell))
          .DataSource(ds => ds.Ajax()
                              .Read(read => read.Action("Get", "Checkins", new { submissionItemId = "#=SubmissionLineItemId#" }))
                              .Update(update => update.Action("Update", "Checkins"))
                              .Create(create => create.Action("Create", "Checkins", new { submissionId = @Model.Id, submissionItemId = "#=SubmissionLineItemId#" }))
                              .Destroy(destroy => destroy.Action("Delete", "Checkins"))
                              .Batch(true)
                              .Model(m =>
                              {
                                  m.Id(ci => ci.Id);
                                  m.Field(ci => ci.StorageArea).Editable(false);
                              })
                              .Events(ev => ev.RequestEnd("updateSubmissionGrid"))
          )
          .ToClientTemplate())

    This all works fine running through Visual Studio (development server). However, when I deploy it to my test server, something (I'm not 100% sure what) causes an error. The message "Uncaught SyntaxError: Unexpected token ILLEGAL" (found in the Console of the Chrome browser tools) appears when I expand a row in the parent grid. Subsequently clicking the "Create" button causes an error on my server-side code, as the IDs ("#=SubmissionLineItemId#") are not substituted. Any idea what could cause this?

  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2206 posts

    Posted 24 Jul 2015 Link to this post

    Hello Harper,


    From the provided information it's not clear for us what is the exact reason for current behavior - could you please provide runable example where the issue can be reproduced? This would help us pinpoint the exact reason for current behavior. 

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Tony
    Tony avatar
    1 posts
    Member since:
    Feb 2013

    Posted 06 Jun 2016 in reply to Harper Link to this post

    Harper,

    Your post is over a year old, so you may have moved on. I had similar symptoms and found that the response returned from the ToClientTemplate method was adding an extra "\n" in the <script> tag for the child grid when it had an editable ForeignKey column. I think it may have something to do with how Telerik encodes the script definition along with the validation for the resulting dropdown list. I was able to work around this by appending:

    .ToHtmlString().Replace("u003e\\n\\u003c", "u003e\\u003c")

    to your Kendo Grid definition. You will then need to wrap the entire call with @Html.Raw()

    The final result should looks something like this:

    @Html.Raw(Html.Kendo().Grid<CheckinViewModel>()
          .Name("grid_#=SubmissionLineItemId#")
          .Columns(cols =>
              {
                  cols.Command(cmd => cmd.Destroy()).Width(100);
                  cols.Bound(ci => ci.Id).Hidden();
                  cols.ForeignKey(ci => ci.StorageAreaId, (IEnumerable)ViewData["storageAreas"], "Id", "Name").Title("Storage Area");
                  cols.Bound(ci => ci.Quantity);
                  cols.Bound(ci => ci.Bags);
                  cols.Bound(ci => ci.Buckets);
                  cols.Bound(ci => ci.Jars);
              })
              .ToolBar(tb =>
              {
                  tb.Create().Text("Add Checkin");
                  tb.Save();
              })
          .Editable(ed => ed.Mode(GridEditMode.InCell))
          .DataSource(ds => ds.Ajax()
                              .Read(read => read.Action("Get", "Checkins", new { submissionItemId = "#=SubmissionLineItemId#" }))
                              .Update(update => update.Action("Update", "Checkins"))
                              .Create(create => create.Action("Create", "Checkins", new { submissionId = @Model.Id, submissionItemId = "#=SubmissionLineItemId#" }))
                              .Destroy(destroy => destroy.Action("Delete", "Checkins"))
                              .Batch(true)
                              .Model(m =>
                              {
                                  m.Id(ci => ci.Id);
                                  m.Field(ci => ci.StorageArea).Editable(false);
                              })
                              .Events(ev => ev.RequestEnd("updateSubmissionGrid"))
          )
          .ToClientTemplate().ToHtmlString().Replace("u003e\\n\\u003c", "u003e\\u003c"))

Back to Top