類型的模型項目我使用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