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

View is showing only data (no grid)

3 Answers 60 Views
SplitView
This is a migrated thread and some comments may be shown as answers.
Alfredo
Top achievements
Rank 1
Alfredo asked on 17 Jun 2020, 01:53 PM

When I call the  following

    /StatusGroups/ my controller code is as follows

public ActionResult GetStatusGroups([DataSourceRequest]DataSourceRequest request)
        {
            var SLAQuery = new OracleLogic();
            return Json(SLAQuery.GetStatusGroupsSLA().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);            
        }

and I get my populated grid using the following view code.

@(Html.Kendo().Grid<NTC_SLA_System.Models.StatusGroupsSLA>()
                                                                                .Name("grid")
                                                                                .Sortable()
                                                                                .Scrollable()
                                                                                .Filterable()
                                                                                .Columns(column =>
                                                                                {
                                                                                    column.Bound(c => c.TYPE_ID).Title("STGID");
                                                                                    column.Bound(c => c.TYPE_NAME).Title("Group Name");
                                                                                    column.Bound(c => c.INGROUPID).Format("{0:0}").Title("in Group");
                                                                                    column.Bound(c => c.ENTERED_DATE).Format("{0:MM-dd-yyyy}").Title("Created On");
                                                                                    column.Bound(c => c.ENTERED_DATE).Format("{0:MM-dd-yyyy}").Title("Modified Date");
                                                                                    column.Bound(c => c.MODIFY_BY).Title("Modified By");
                                                                                    column.Bound(c => c.TYPE_ID).ClientTemplate("<a class='ntc-blue' href=\"" + Url.Action("ViewType", new {                                                                                      ID = "#=TYPE_ID#" }) + "\">View</a>").Title("Action");
                                                                                })
          .DataSource(dataSource => dataSource

           .Ajax()
           .Model(model => model.Id(p => p.Id))
            .Read(read => read.Action("GetStatusGroups", "StatusGroups"))
            .ServerOperation(false)
            .PageSize(20))

If I click on View in that Grid I go to /StatusGroups/ViewType/1

My controller code is as follows

public ActionResult ViewType([DataSourceRequest]DataSourceRequest request, string id = null)
        {
            var SLAQuery = new OracleLogic();
            return Json(SLAQuery.GetStatusGroupsViewSLA(id).ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }  

and my view code is

 @(Html.Kendo().Grid<NTC_SLA_System.Models.StatusGroupsViewSLA>()

                                .Name("grid")
                                .Sortable(sortable => sortable
                                .AllowUnsort(true)
                                .SortMode(GridSortMode.MultipleColumn)
                                .ShowIndexes(true))
                                .Scrollable()                                
                                .Columns(column =>
                                {
                                    column.Bound(c => c.STATUS_NAME).Template(c => c.STATUS_ID + "&nbsp-&nbsp" + c.STATUS_NAME).Title("To Status Name");
                                    column.Bound(c => c.STATUS_ID).Template(@<text>@Html.ActionLink("Remove", "ViewType", new { id = @item.STATUS_ID })                                                    </text>).Title("Action").Sortable(false).HtmlAttributes(new { @class = "center-text" });
                                })

.DataSource(datasource => datasource
                                        .Ajax()
                                        .Model(model =>
                                        {                                                                                        
                                            model.Field(f => f.STATUS_NAME);                                            
                                        })
                                        .Read(read => read.Action("ViewType", "StatusGroups"))                                        
                                )
The Grid result is empty no data.

3 Answers, 1 is accepted

Sort by
0
Alfredo
Top achievements
Rank 1
answered on 17 Jun 2020, 01:58 PM

I forgot if I change my controller code to return Json without a View as

public ActionResult ViewType([DataSourceRequest]DataSourceRequest request, string id = null)
        {
            var SLAQuery = new OracleLogic();
            return Json(SLAQuery.GetStatusGroupsViewSLA(id).ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }  

I only get the display row data in Json format but no grid.

 

0
Alfredo
Top achievements
Rank 1
answered on 17 Jun 2020, 06:41 PM

I figure out the issue and made it work like this:

public ActionResult ViewType([DataSourceRequest]DataSourceRequest request, string id = null)
        {
            var SLAQuery = new OracleLogic();
            ViewBag.ViewType = SLAQuery.GetStatusGroupsViewSLA(id);
            return View();

}

And the view I change it to

@(Html.Kendo().Grid((IEnumerable<NTC_SLA_System.Models.StatusGroupsViewSLA>)ViewBag.ViewType)

Now I am trying to Add a new row (InLine) in the grid and is not working.

0
Nikolay
Telerik team
answered on 19 Jun 2020, 12:48 PM

Hi Alfredo,

Thank you for the updates on the case.

I see that you have managed to display Grid's data via local binding, however, If you would like to have edited (add new records) enabled the Grid will still perform Ajax request which basically makes the local binding lose its purpose. I would recommend setting the Grid for remote binding.

More information can be obtained in the following documentation article:

For your convenience, I am attaching a demo MVC project demonstrating how a Grid that uses CRUD operations

Let me know if you have any questions.

 Regards,
Nikolay
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
SplitView
Asked by
Alfredo
Top achievements
Rank 1
Answers by
Alfredo
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or