Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > The model item passed into the dictionary is of type 'Telerik.Web.Mvc.GridModel', but this dictionary requires a model item of type

Not answered The model item passed into the dictionary is of type 'Telerik.Web.Mvc.GridModel', but this dictionary requires a model item of type

Feed from this thread
  • Kags avatar

    Posted on Jul 22, 2012 (permalink)

    I have form with a Telerik grid. Within the grid toolbar, I have a custom button which I would like to open a popup window to insert a new record.


    I have followed the Popup Form with Server/Client Validation in Window - Example and modified it to fit my scenario. However, running the application generates the following error 

    The model item passed into the dictionary is of type  'Telerik.Web.Mvc.GridModel', but this dictionary requires a model item  of type 'Web.Models.OwnerViewModel'.

    Below is an extract from the view that is hosting the grid

        @using Telerik.Web.Mvc.UI
        @{
           ViewBag.Title = "Owner Listing";
        }

        @model Web.Models.OwnerViewModel
        @{  Html.Telerik().Window()
            .Name("Window")
            .Title("Add New Owner")
            .Content(@<text>
                @using (Html.BeginForm("Create", "Owner", FormMethod.Post, new { id = "AddNewOwnerForm" }))
                {
                    @Html.LabelFor(model => model.FullName)
                    @Html.EditorFor(model => model.FullName)

                    @Html.LabelFor(model => model.Telephone)
                    @Html.EditorFor(model => model.Telephone)
                    <div class="form-actions">
                        <button type="submit" class="t-button t-state-default">Save</button>
                    </div>
                }
                </text>)
            .Width(400)
            .Draggable(true)
            .Modal(true)
            .Visible(false)
            .Render();
        }
        <div>
            @(Html.Telerik().Grid<Web.Models.OwnerViewModel>()
            .Name("Vehicles")
            .ToolBar(commands => commands.Custom()
                .Action("Create", "Owner")
                .Name("btnAddNewOwner")
                .Text("Add Vehicle")
                .HtmlAttributes(new { id = "btnAddNewOwner" })
            )
            .DataKeys(keys => keys.Add(v => v.Id).RouteKey("Id"))
            .Columns(columns =>
            {
                columns.Command(cmd =>
                {
                    cmd.Edit().ButtonType(GridButtonType.Image);
                }).Width(40);
                columns.Bound(v => v.FullName).Width(150);
                columns.Bound(v => v.Telephone).Width(150);
                columns.Bound(v => v.Address).Width(150);
            })
            .DataBinding(dataBinding => dataBinding.Ajax()
                .Select("Index", "Owner")
                .Update("Edit", "Owner"))
            .Pageable(paging => paging.PageSize(10))
            .Scrollable()
            .Filterable()
            .Sortable()
            )
            )
        </div>


    The following is the controller code for the grid

         [GridAction]
            public ActionResult Index()
            {
                var owners = _ownerService.ListAll();        
                return View(new GridModel( owners ));
            }

    and the following is the controller code for Create

            public PartialViewResult Create()
            {
                SetSelectionLists();
                var model = new OwnerViewModel();
                return PartialView( "Create", model);
            }

     I would appreciate any help or a pointer to the right direction.

    Reply

  • Hetal avatar

    Posted on Aug 12, 2012 (permalink)

    Hello...

    Actually the model requires OwnerViewModel type and it is getting another type.

    Try in your 'Index' action method following...

    OwnerViewModel owners =_wnerService.ListAll();


    make sure that _wnerService.ListAll() returns value of the type OwnerViewModel .

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > The model item passed into the dictionary is of type 'Telerik.Web.Mvc.GridModel', but this dictionary requires a model item of type