Asp.net mvc KendoUI listview传递IEnumerable<;模型>;而不是MVC中编辑器模板中的模型
这件事我已经困惑了好几天了。基本上,我有一个视图模型,它包含其他视图模型的三个IEnumerables,将显示在三个单独的Kendo控件中——一个作为ListView,两个作为GridView。每个视图模型都有一个单独的编辑器模板,由相应的控件使用。GridView 100%正常工作,Kendo ListView在页面上正常工作(ListView使用更新的数据刷新) 我的问题是,视图模型的IEnumerable被传递给ActionResult(使用空值),而不是视图模型的单个实例,并且DataSourceRequest是空的。 这是(修订过的)代码 视图模型(仅是相关ListView的包装器和视图模型):Asp.net mvc KendoUI listview传递IEnumerable<;模型>;而不是MVC中编辑器模板中的模型,asp.net-mvc,listview,kendo-ui,ienumerable,mvc-editor-templates,Asp.net Mvc,Listview,Kendo Ui,Ienumerable,Mvc Editor Templates,这件事我已经困惑了好几天了。基本上,我有一个视图模型,它包含其他视图模型的三个IEnumerables,将显示在三个单独的Kendo控件中——一个作为ListView,两个作为GridView。每个视图模型都有一个单独的编辑器模板,由相应的控件使用。GridView 100%正常工作,Kendo ListView在页面上正常工作(ListView使用更新的数据刷新) 我的问题是,视图模型的IEnumerable被传递给ActionResult(使用空值),而不是视图模型的单个实例,并且DataS
public类MainPersonViewModel
{
公共MainPersonViewModel(){}
公共int PersonId{get;set;}
公共IEnumerable个人详细信息{get;set;}
公共数字
剑道控制本身:
@(Html.Kendo().ListView<Staff.ViewModels.DetailsViewModel>(Model.PersonDetails)
.Name("personDetailsList")
.TagName("div")
.ClientTemplateId("personDetailsTemplate")
.Editable()
.DataSource(ds => ds
.Model(m =>
{
m.Id(f => f.PersonId);
m.Field(f => f.Name);
m.Field(f => f.WorkingTitle);
}
)
.Read(read => read.Action("ViewPersonDetails", "Staff", new {id = Model.PersonId}))
.Update(update => update.Action("UpdatePersonDetails", "Staff"))
)
@(Html.Kendo().ListView(Model.PersonDetails)
.名称(“个人名单”)
.TagName(“div”)
.ClientTemplateId(“personDetailsTemplate”)
.可编辑()
.DataSource(ds=>ds
.Model(m=>
{
m、 Id(f=>f.PersonId);
m、 字段(f=>f.Name);
m、 字段(f=>f.WorkingTitle);
}
)
.Read(Read=>Read.Action(“ViewPersonDetails”,“Staff”,new{id=Model.PersonId}))
.Update(Update=>Update.Action(“UpdatePersonDetails”、“Staff”))
)
)
控制器中的Listview调用的ActionResult如下所示:
public class StaffController : Controller
{
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdatePersonDetails([DataSourceRequest] DataSourceRequest request, IEnumerable<DetailsViewModel> toUpdate)
{
//update code here
return Json(ModelState.ToDataSourceResult());
}
}
公共类StaffController:控制器
{
[接受动词(HttpVerbs.Post)]
public ActionResult UpdatePersonDetails([DataSourceRequest]DataSourceRequest请求,IEnumerable toUpdate)
{
//在此更新代码
返回Json(ModelState.ToDataSourceResult());
}
}
最后,编辑器模板(位于Views\Staff\EditorTemplates中):
@model Staff.ViewModels.DetailsViewModel
@LabelFor(m=>m.NameFirst)
@EditorFor(m=>m.NameFirst)
@LabelFor(m=>m.NameLast)
@EditorFor(m=>m.NameLast)
@LabelFor(m=>m.Title)
@EditorFor(m=>m.Title)
由于ListView似乎正在刷新,我认为它或页面上的数据源不一定有问题,所以我倾向于使用我所缺少的编辑器模板的一些细节(即限制)。有什么想法吗
很抱歉发布了这么长的帖子,如果有任何帮助,我们将不胜感激!只是更新:我从未解决过这个问题,但在将剑道网格添加到页面之前,我放弃了当前视图并从列表视图开始重新构建,从而使列表视图正常工作。没有对编辑器模板或任何类文件进行任何更改。
@(Html.Kendo().ListView<Staff.ViewModels.DetailsViewModel>(Model.PersonDetails)
.Name("personDetailsList")
.TagName("div")
.ClientTemplateId("personDetailsTemplate")
.Editable()
.DataSource(ds => ds
.Model(m =>
{
m.Id(f => f.PersonId);
m.Field(f => f.Name);
m.Field(f => f.WorkingTitle);
}
)
.Read(read => read.Action("ViewPersonDetails", "Staff", new {id = Model.PersonId}))
.Update(update => update.Action("UpdatePersonDetails", "Staff"))
)
public class StaffController : Controller
{
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdatePersonDetails([DataSourceRequest] DataSourceRequest request, IEnumerable<DetailsViewModel> toUpdate)
{
//update code here
return Json(ModelState.ToDataSourceResult());
}
}
@model Staff.ViewModels.DetailsViewModel
<div>
<table>
<tr>
<td>@Html.LabelFor(m => m.NameFirst)</td>
<td>@Html.EditorFor(m => m.NameFirst)</td>
</tr>
<tr>
<td>@Html.LabelFor(m => m.NameLast)</td>
<td>@Html.EditorFor(m => m.NameLast)</td>
</tr>
<tr>
<td>@Html.LabelFor(m => m.Title)</td>
<td>@Html.EditorFor(m => m.Title)</td>
</tr>
<tr>
<td colspan="2">
<div class="edit-buttons">
<a class="k-button k-button-icontext k-update-button" href="\\#"><span class="k-icon k-update"></span>Save</a>
<a class="k-button k-button-icontext k-cancel-button" href="\\#"><span class="k-icon k-cancel"></span>Cancel</a>
</div>
</td>
</tr>
</table>
</div>