类型的模型项目我使用Telerik网格创建窗体。在网格工具栏中,我有一个自定义按钮,我想打开一个弹出窗口来插入新记录。传递到字典中的模型项目类型为“Telerik.Web.Mvc.GridModel”,但是此字典需要
我跟着Popup Form with Server/Client Validation in Window - Example并修改它以适应我的情况。然而,运行的应用程序生成以下错误
传递到词典中的模型项的类型 “Telerik.Web.Mvc.GridModel”的,但本词典需要模型项类型的 “Web.Models .OwnerViewModel”。
下面是从视图的提取物承载在网格
@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>
以下是针对网格
[GridAction]
public ActionResult Index()
{
var owners = _ownerService.ListAll();
return View(new GridModel(owners));
}
控制器代码和以下是用于创建的控制器编码
public PartialViewResult Create()
{
SetSelectionLists();
var model = new OwnerViewModel();
return PartialView("Create", model);
}
我看过在stackoverflow类似的问题,但似乎没有解决我面临的问题。我将不胜感激任何帮助或指向正确的方向。
你解决这个问题?我遇到了同样的问题。 – gunnerz 2013-03-22 17:18:31