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

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

1 Answer 319 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kags
Top achievements
Rank 1
Kags asked on 22 Jul 2012, 05:23 PM
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.

1 Answer, 1 is accepted

Sort by
0
Hetal
Top achievements
Rank 1
answered on 13 Aug 2012, 04:18 AM
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 .
Tags
General Discussions
Asked by
Kags
Top achievements
Rank 1
Answers by
Hetal
Top achievements
Rank 1
Share this question
or