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

ID is an empty guid in the Update & Destroy methods.

3 Answers 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cool Breeze
Top achievements
Rank 1
Cool Breeze asked on 21 Mar 2014, 05:17 AM
I have a grid that when it tries to update, the ID field of my model is an empty guid when it gets back to the controller. I am displaying the column in the guid and the value is definitely there. What would cause the ID to be stripped out like that?

Here is my view with the grid:

@model List<Common.Models.Brand>
 
@{
    ViewBag.Title = "Maintain Brands";
}
 
<h2>Maintain Brands</h2>
 
@(Html.Kendo().Grid(Model)
    .Name("MaintainBrandsGrid")
    .Columns(columns =>
    {
        columns.Bound(brand => brand.BrandId).Title("Id");
        columns.Bound(brand => brand.BrandName).Title("Brand Name");
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(185);
    })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable(scr=>scr.Height(430))
    .Filterable()   
    .DataSource(dataSource => dataSource       
        .Ajax()
        .PageSize(20)
        .ServerOperation(false)
        .Model( model => model.Id( brand => brand.BrandId))
        .Create( create => create.Action("AddBrand", "BrandMaintenance"))
        .Update( update => update.Action("UpdateBrand", "BrandMaintenance"))
        .Destroy( delete => delete.Action("RemoveBrand", "BrandMaintenance"))
        )       
     )

And here is the UpdateBrand method from the BrandMaintenance controller:

//
        // POST: /BrandMaintenance/UpdateBrand
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult UpdateBrand([DataSourceRequest]
                                        DataSourceRequest request, Brand brand)
        {
            if (brand != null && ModelState.IsValid)
            {
                var bll = new CatalogMaintenanceBll();
                bll.UpdateBrand(brand);
            }
 
            return Json(new[] { brand }.ToDataSourceResult(request, ModelState));
        }

I have several other grids that were created the exact same way and they are all working, so I am wondering what I could possibly be missing that could cause this.

Thanks for any help!








3 Answers, 1 is accepted

Sort by
0
Cool Breeze
Top achievements
Rank 1
answered on 21 Mar 2014, 05:37 AM
Hmm strange. I deleted the model and added both properties back, same problem. I inspected ModelState and it only had a reference to the BrandName property. Weird. I added another Guid property to my model and tried again. This time the ModelState had a reference to the BrandName property and the new Guid property. I deleted the old BrandId property and rebuilt. Then I renamed the new guid property to BrandId, rebuilt again and it works. Not really sure what to say about all that.
0
Nikolay Rusev
Telerik team
answered on 25 Mar 2014, 07:33 AM
Hello Joe,

Seems that you've managed to resolve the issue on your own. Thus I'm closing this thread.

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Cool Breeze
Top achievements
Rank 1
answered on 25 Mar 2014, 06:07 PM
That is fine with me since there is no real solution to follow.
Tags
Grid
Asked by
Cool Breeze
Top achievements
Rank 1
Answers by
Cool Breeze
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or