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

Kendo Grid Create method issues/help

2 Answers 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 20 Mar 2013, 04:23 PM
EDIT:: Figured something out

if I change :: 
 Create([DataSourceRequest] DataSourceRequest request, Property model)

TO:: Create([DataSourceRequest] DataSourceRequest request, Property <ANY OTHER WORD BUT model> )

it works.  _model, data, stuff

Please any clues, and or answers would be great.


I apologize if this has been covered elsewhere, I have looked and not found an answer.

the issue is as follows:

I have a kendo grid on a strongly typed view  see below:

<div style="margin: 0 1em; width: 940px">
    @(Html.Kendo().Grid<WebClaims.Common.Models.Property>(Model.OtherProperties)
        .Name("OtherProperties")
        .Columns(columns =>
        {
            columns.Bound(p => p.Make).HeaderTemplate("Vehicle").HeaderHtmlAttributes(new { style = "width:30%;" });
            columns.Bound(p => p.Model).HeaderHtmlAttributes(new { style = "display:none;" });
            columns.Bound(p => p.Year).HeaderHtmlAttributes(new { style = "display:none;" });
            columns.Bound(p => p.Driver.FirstName).HeaderHtmlAttributes(new { style = "display:none;" });
            columns.Bound(p => p.Driver.LastName).HeaderTemplate("Driver Info");
            columns.Command(cmd => cmd.Edit());

        })
       .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("Property"))
        
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(m=>{
                m.Id(p => p.ID);
                m.Field(p => p.ID).DefaultValue(Guid.NewGuid());
                m.Field(p => p.Make).DefaultValue("Unknown");
                m.Field(p => p.Model).DefaultValue("Unknown");
                m.Field(p => p.Year).DefaultValue(DateTime.Now.Year);
                m.Field(p => p.Driver).DefaultValue(WebClaims.Common.Models.Claimant.Default());
            })
            .Read(read =>{
                read.Action("Read", "OtherPropertiesGrid");

            })
            .Create(create=> {
                create.Action("Create","OtherPropertiesGrid").Type(HttpVerbs.Post);
            })
            .Update(u =>{
                u.Action("Update", "OtherPropertiesGrid");
            })
            .Destroy(u =>{
                u.Action("Destroy", "OtherPropertiesGrid");
            })
            
        )
        .ToolBar(t=>{
            t.Create();
           
        })
        .Sortable()
        .Scrollable()
    )
    </div>



the Create will open the editor template and when the update button is pressed it fires the Create Action on the controller however, i must be doing something wrong as the model that is passed is null:

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([DataSourceRequest] DataSourceRequest request, Property model)
        {                                                                                                    this is populated^               this is NULL ^
            WebClaims.Common.Models.Claim c = Session["claim"] as WebClaims.Common.Models.Claim;
             //DO stuff //
            return Json(c.OtherProperties.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);

        }

something else thats a bit off is that the edit command fires the create action not the update?? 


If I populate the list of stuff I want to see before hand the read call works, 

I'm not sure what I'm doing wrong... any and all help would be great.

thanks 


2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 22 Mar 2013, 08:52 AM
Hi Jimm,

 
After reviewing the provided information it seems that the issue comes from that the current model contains property "Model" and the MVC model binder tries to bind it to the "model" variable that the action expects. In current case I would suggest to use different name for the accepted model in the controller action.


Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
James
Top achievements
Rank 1
answered on 22 Mar 2013, 04:03 PM
Thanks, Vladimir you were indeed correct.  Looks as though this is an undocumented feature of MVC, dont know how long it would have taken us to find that out.

Again,  Thanks
Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
James
Top achievements
Rank 1
Share this question
or