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

[Solved] MVC Model not working

4 Answers 263 Views
Grid
This is a migrated thread and some comments may be shown as answers.
crazy05
Top achievements
Rank 1
crazy05 asked on 12 Mar 2015, 07:41 PM
If I bulid the grid with Model, it is working. But If I Pass the same model to the partial, it is not working. It is throwing an error message saying.The model item passed into the dictionary is of type 'Models.Asset', but this dictionary requires a model item of type 'System.Collections.Generic.List`1Below is my Kendo grid and here is my Partial

@Html.Partial("_Address", Model.Address)

@(Html.Kendo().Grid(Model.Address)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Id).Hidden();
columns.Bound(p => p.Address).Width(300);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.Events(events =>
{
events.Save("onSave");
events.Edit("onEdit");

})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.ToolBar(toolBar =>
{
toolBar.Create().Text("Add Address");
})
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("onError"))
.Model(model => model.Id(p => p.Address))
.ServerOperation(false)
)
)

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 16 Mar 2015, 03:28 PM
Hello,

Can you paste here the complete declaration of your partial view? We want to check how the @model is set up. If it is @IEnumerable<Address> then you should use the grid like this @(Html.Kendo().Grid(Model)

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
crazy05
Top achievements
Rank 1
answered on 16 Mar 2015, 03:30 PM
[quote]Your quote goes here[/quote]Hello,

It is working. I forgot to define schema. 

I have one more question related to this. I am using this Kendo Grid as Partial View. Everytime I use this grid in a page, I have to write OnEdit and OnSave function in every page. How can I get rid of this ?
0
Atanas Korchev
Telerik team
answered on 18 Mar 2015, 07:17 AM
Hello,

You can define the event handlers in the partial view itself. Have you tried this?

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
crazy05
Top achievements
Rank 1
answered on 18 Mar 2015, 12:26 PM
Yes, I tried it. But not working. So create a seperate js file and reference that file in every page
Tags
Grid
Asked by
crazy05
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
crazy05
Top achievements
Rank 1
Share this question
or