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 have looked at similar questions on stackoverflow but non seems to address the problem I am facing. I would appreciate any help or a pointer to the right direction.