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

Grid Create Method not responding

2 Answers 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 11 Jun 2014, 02:06 PM
Hello, 

I have been evaluating the grid and I cant seem to get the Create method to work , no reaction on the grid. The edit works fine, which is using the custom template. The grid is configured to work in the popup edit mode. 

Perhaps I am missing something small, but even the sample project that i downloaded from the code library (foreignkeydemo) doesnt work. 

I have followed the examples in the documentation to no avail. 

Here is the code below, i would appreciate if anyone can point me in the right direction or perhaps some documentation that i might have missed. 

Thanks in advance. 

Max. 

Index.cshtml. 

@using PMTrack   
 
    
<script type="text/kendo" id="memberTemplate">
        <ul>  
            #for(var i=0; i<data.length; i++){#
            <li> #:data[i].Firstname +" "+ data[i].Lastname #</li>
         #}#
          
        </ul> 
</script> 

<script type="text/javascript">
   var memberTemplate = kendo.template($("#memberTemplate").html(), {useWithBlock:false})
</script>

@(Html.Kendo().Grid<Project>()
      .Name("grid")
      .Columns(columns =>
          {
              columns.Bound(p => p.Id).Width(5).Title("#").Filterable(false);
              columns.Bound(p => p.Name).Width(60).Title("Project name");
              columns.Bound(p => p.StartDate).Width(50).Filterable(true).Format("{0:dd/MM/yyyy}");
              columns.Bound(p => p.PlannedEndDate).Width(50).Format("{0:dd/MM/yyyy}");
              columns.Bound(p => p.Status).Width(20);
              columns.Bound(p => p.Members).ClientTemplate("#=memberTemplate(Members)#").Width(100);
              columns.Bound(p => p.Owner.Firstname).ClientTemplate("#=Owner?Owner.Firstname:''#").Title("Owner").Width(50);
              columns.Command(command =>
                  {
                      command.Edit();
                      command.Destroy();
                      

                  }).Width(40); 
                                                                                                                                                          
          } )
      .ToolBar(toolbar =>  toolbar.Create().Text("New Project"))
      .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("ProjectEditorTemplate"))
      .Pageable()
      .Sortable()
      .HtmlAttributes( new { style="width:900px"})
      .Filterable()
      .DataSource(ds => ds.Ajax().Events(e => e.Error("onError"))
                          .PageSize(20)
                          .Model(model => model.Id(p =>p.Id))
                          .Read(read => read.Action("Read", "Home"))
                          .Update(update=> update.Action("Update", "Home"))
                          .Destroy(destroy => destroy.Action("Delete", "Home"))
                          .Create(create => create.Action("Insert", "Home").Type(HttpVerbs.Post))
      ))
  
<script type="text/javascript">
    function onError(e) {
        if (e.errors) {
            var message = "Errors:\n";
            $.each(e.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            alert(message);
        }
    }
</script>



<script>
    $(document).ready(function () {
        kendo.culture("en-GB");

    });
</script>


The Controller : 
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
        {

            var ps = new ProjectService();


            return Json(ps.Read().ToDataSourceResult(request));

        }
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, Project project)
        {
            if (project != null && ModelState.IsValid)
            {
                var ps = new ProjectService();
                ps.Update(project);

            }
            return Json(new[] { project }.ToDataSourceResult(request, ModelState));
        }

        public ActionResult Delete([DataSourceRequest] DataSourceRequest request, Project project)
        {
            if (project != null)
            {
                var ps = new ProjectService();
                ps.Delete(project);
            }

            return Json(new[] { project }.ToDataSourceResult(request, ModelState));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Insert([DataSourceRequest] DataSourceRequest request, Project project)
        {


            if (project != null && ModelState.IsValid)
            {
                var ps = new ProjectService();
                ps.Create(project);
            }


            return Json(new[] { project }.ToDataSourceResult(request, ModelState));
        }


        public ActionResult Index()
        {
            var ms = new MemberService();

            var members = ms.GetAll();

            var status = new List<string>
                {
                    "Development",
                    "Validation"
                };


            ViewData["status"] = status;

            ViewData["owners"] = members;

            ViewData["members"] = members;

            return View();
        }








2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 13 Jun 2014, 09:00 AM
Hi Max,

Basically the current Grid configuration looks valid - could you please record screencast which to show the browser console as well as the request parameters that are send to the "Insert" action on the server (similar to this one)?

Kind Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Max
Top achievements
Rank 1
answered on 16 Jun 2014, 10:50 AM
I found the solution, i had to modify the model to include the Members and Owner classes, now it works fine. 

.Model(model =>
                              {
                                  model.Id(p => p.Id);
                                  model.Field(p => p.Owner).DefaultValue(new Member());
                                  model.Field(p => p.Members).DefaultValue(new List<Member>()); 
                              })
Tags
Grid
Asked by
Max
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Max
Top achievements
Rank 1
Share this question
or