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

MVC Grid Hierarchy Form Post Data

1 Answer 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 10 Jul 2017, 01:07 PM

I Am not sure if this can even be done, but from what I have read it should be.  Since the Grid is not a form control, I should be able to use templates to generate the controls and have MVC generate the proper HTML when rendered.  I started off using Dave Glick's "how to post data in a KendoUI grid in MVC https://daveaglick.com/posts/how-to-post-data-in-a-kendoui-grid  I also used the Telerik Example at GitHub https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/post-grid-with-form  both were very helpful with getting a "first level" Grid to post data, however not for the Second Level.  

 

So I am not even sure if this is possible, but I have what I think *should work) if I can get the data into the template and then on to the Grid.  The first problem I am having is that I can't get any of the Grid Values in the Template for the 2nd level to "insert" I CAN get the  #=WOID# to show but none of the others

#=GRIDID#
#=MAPNAME#
#=PAGENUMBER#
#=SCALE# 

I am getting a JS error saying that    GIDID is not defined.  But WOID works and it's not defined..  what am I missing?   Also when I just use the WOID and post data the posted data is not a collection, it is one record (only the WOID) 

 

@using (Html.BeginForm("REREQUEST", "GridPrint"))
{
 
@(Html.Kendo().Grid(new List<GRIDPRINTWO>())   //<GISPortal.GRIDPRINTWO>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(e => e.WOID).Width(40).Title("WO#");
            columns.Bound(e => e.REQUESTDATE).Width(150).Format("{0:G}").Title("Date");
            columns.Bound(e => e.REQUESTER).Width(100).Title("Requester#");
            columns.Bound(e => e.NOTIFICATIONTYPE).Width(110).Title("Notification");
            columns.Bound(e => e.COMPLETED).Width(110).Title("Completed?");
            columns.Bound(e => e.ERRORS).Title("Errors?");
 
        })
        .Sortable()
        .Pageable()
        .Scrollable()
        .ClientDetailTemplateId("template")
         
        .HtmlAttributes(new { style = "height:600px;" })
        .DataSource(dataSource => dataSource
        .Ajax()
        .Sort(sort => sort.Add("REQUESTDATE").Descending()) // <-- initial sort expression
        .PageSize(20)
             // .Read(read => read.Action("GRIDPRINTWO_Read", "Grid"))
                    .Read(read => read.Action("GRIDPRINTWO_Read", "GridPrint", new { woid = ViewBag.woid, requester = ViewBag.requester }))
        )
        .Events(events => events.DataBound("dataBound"))
         
         
)
 
 
    <script>
          var counter = 1;
 
 
        function gridIndex(data) {
         return counter++;
                                  }
    </script>
 
    <script>
 
    function index(dataItem) {
        var data = $("#Products").data("kendoGrid").dataSource.data();
 
        return data.indexOf(dataItem);
    }
 
    </script>
 
<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid(new List<GRIDPRINTS>())  //<GISPortal.GRIDPRINTS>()
            .Name("grid_#=WOID#") // template expression, to be evaluated in the master context
            .Columns(columns =>
            {
                columns.Bound(o => o.MAPNAME).Width(110).Title("Name");
                columns.Bound(o => o.GRIDID).Width(110).Title("GridID");
                columns.Bound(o => o.SCALE).Width(110).Title("Scale");
                columns.Bound(o => o.PAGENUMBER).Title("PageNum");    
                columns.Bound(o => o.STATUS).Width(200).Title("Status");
                columns.Bound(o => o.ERRORS).Width(300).Title("Errors?");
                 
                 
                 
                // shout out to daveaglick.com/posts/how-to-post-data-in-a-kendoui-grid
               //  HERE IS WHERE I AM HAVING ISSUES
                 
                columns.Bound(m => m.GRIDID).Hidden()
                  .ClientTemplate("<input type='hidden' "
                  + "name='THEGRIDID[#=gridIndex(data)#].GRIDID' "
                  + "value='#=GRIDID#' />");
                  // ALSO TRIED THIS  + "value='@item.GRIDID' />");
                 
                 columns.Bound(m => m.MAPNAME).Hidden()
                  .ClientTemplate("<input type='hidden' "
                  + "name='THEMAPNAME[#=gridIndex(data)#].MAPNAME' "
                  + "value='#=MAPNAME#' />");              
                 
                columns.Bound(m => m.PAGENUMBER).Hidden()
                  .ClientTemplate("<input type='hidden' "
                  + "name='THEPAGENUMBER[#=gridIndex(data)#].PAGENUMBER' "
                  + "value='#=PAGENUMBER#' />");
                 
                columns.Bound(m => m.SCALE).Hidden()
                  .ClientTemplate("<input type='hidden' "
                  + "name='THESCALE[#=gridIndex(data)#].SCALE' "
                  + "value='#=SCALE#' />");
                                 
            
               // JUST PLAYING HERE BUT THE WOID DOES WORK    
                columns.Bound(o => o.MAPNAME).Width(110).Title("Re-Send")
                     .ClientTemplate("<input type='checkbox' "
                     + "name='CHECKED[#= WOID #].MAPNAME' "
                     + "value='true' "
                     + "#if (WOID) { #checked='checked'# } #/>"
                     + "<input type='hidden' value='false' "
                     + "name='themapname[#= WOID #].MAPNAME' />");
            })
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(10)
                .Read(read => read.Action("GRIDPRINTS_Read", "GridPrint", new { woid = "#=WOID#" }))
                .ServerOperation(false)
            )
            .Pageable()
            .Sortable()
            .ToClientTemplate()
    )
</script>
<script>
    function dataBound() {
       // this.expandRow(this.tbody.find("tr.k-master-row").first());
    }
</script>
 
 
 
 
    <input type="submit" value="SUBMIT" />
 
 
}

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 12 Jul 2017, 08:55 AM

Hello Jason,

The problem you are facing is that the values that are evaluated against the model of the child grid should be escaped as explained in Hash Literals article. When they are no escaped they are evaluated against the model of the parent grid. This is why #=WOID# is a field of the parent model. All other expressions that evaluates fields from the child grid should be escaped. 

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or