【发布时间】:2014-06-16 20:23:00
【问题描述】:
我正在开发一个带有 kendo UI 网格的 MVC。其中我有网格和一个按钮。网格包含复选框。当我们点击按钮复选框值(真/假)和记录ID应该去行动结果。
using (Html.BeginForm("Update", "Model"))
{
Html.Kendo().Grid(Model.Users)
.Name("grid")
.Columns(columns =>
{
columns.Bound(o => o.UserName).Width("300px");
columns.Bound(o => o.IsLicensed).Template(o =>
{%><%: Html.CheckBox("license",o.IsLicensed)%> <%: Html.Hidden("id", o.UserId) %><%}).Width("200px");
})
.Resizable(resize => resize.Columns(true))
.Sortable(sorting => sorting.Enabled(true))
.Filterable(f => f.Enabled(true))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(new int[] {10, 20, 50, 100})
.ButtonCount(5))
.Render();
%>
<p>
<input class="k-primary k-button" type="submit" value="Save" name="selectedValues"/>
</p>
<%
Html.EndForm();
}
%>
</div>
<% });
我的操作结果如下所示
public ActionResult Update(string[] license, string[] id)
现在我在这里使用 ajax 绑定并提供数据源。所以我不能使用模板。我们需要使用 ClientTemplate。 ClientTemplate 代码更改如下所示。
.Columns(columns =>
{
columns.Bound(o => o.UserName).Width("300px");
columns.Bound(o => o.IsLicensed).Width("300px").ClientTemplate("<input type='checkbox' name='license' ${ IsLicensed == true ? checked='checked' : ''} enabled />" + "<input type='hidden' name='id' value='#= UserId#' />");
})
.DataSource(datasource => datasource.Ajax().Read(read => read.Action("Customers_Read", "UsersLicensing")).PageSize(10))
.Render();
在以前的情况下,当调用 Update actionresult 时,两个参数都是 10 的数组,因为 pagesize 是 10,我可以更新数据库。但在这种情况下(使用 ajax 和 clientTemplate)id 参数作为 10 个项目的数组出现,但许可证参数取决于所选复选框的数量(如果选择了 3 个复选框,则许可证包含 3 个元素)。所以我无法进行一对一的映射。
有人可以帮我解决这个问题或提出更好的主意吗?
【问题讨论】:
标签: ajax asp.net-mvc checkbox kendo-ui kendo-grid