【发布时间】:2014-11-06 12:04:21
【问题描述】:
Here is My grid, When Checkbox is Selected I want to pass the CheckBox Checked/Not Checked Value to Controller.在控制器模型中访问时不会保留 Checkbox 值。你能指导我实现它吗?
我的观点:
@using(@Html.BeginForm("RequisitionApply", "Requisition", FormMethod.Post, new { approvalReason = Model, @id = "addExpenseItem" }))
{
@(Html.Kendo().Grid<ZCW.MVC.ViewModels.ManagerRequisitionSearchListViewModel>()
.Name("ManagerRequisitionApprovalGrid")
.DataSource(dataSource => dataSource
.Ajax()
.Events(e => e.RequestEnd("GetPaginationDisplay"))
.PageSize(25)
.Read(read => read.Action("GetDetails", "List").Type(HttpVerbs.Get))
//.Update(update => update.Action("Apply", "List").Type(HttpVerbs.Post))
.ServerOperation(true)
)
.Columns(columns =>
{
//RequistionName(ID)
columns.Bound(p => p.FirstName).ClientTemplate("#=FirstName#<a href='" + Url.Action("GetResource", "List", new { NameID = "#=NameID#"}) + "'>(#=NameID#) </a>").Title(@Html.LocalizedText("ID")).HtmlAttributes(new { @class = "alignleft" });
//Location
columns.Bound(p => p.Location)
.Title(@Html.LocalizedText("Location")).HtmlAttributes(new { @class = "alignleft" });
// Accept Header
columns.Template(p => p.Accept).Title("")
.HeaderTemplate("<i class='icon-ok gicn tooltips' data-original-title='Approve' data-placement='top'></i><br><div class='checker'><span><input id='selectallApprove' class='chkboxApprove' type='checkbox' onclick='ToggleChkBoxApprove(this.checked);' #= Accept ? checked='checked' : '' # /></span></div>")
.ClientTemplate("<span> <input id='checkbox' onclick='grdChkBoxClick(this); ' class='chkboxApprove' type='checkbox' name='remember' /></span>")
.HeaderHtmlAttributes(new { @class = "aligncenter" })
.HtmlAttributes(new { @class = "textaligncenter" });
//Decline Header
columns.Template(p => p.Decline).Title("")
.HeaderTemplate("<i class='icon-remove ricn tooltips' data-original-title='Decline' data-placement='top'></i><br><div class='checker'><span> <input id='selectallDecline' class='chkboxDecline' type='checkbox' onclick='ToggleChkBoxDecline(this.checked);' #= Decline ? checked='checked' : '' # /></span></div>")
.ClientTemplate("<span> <input id='checkbox1' onclick='grdChkBoxClick(this); ' class='chkboxDecline' type='checkbox' name='remember'/></span>")
.HeaderHtmlAttributes(new { @class = "aligncenter" })
.HtmlAttributes(new { @class = "textaligncenter" });
})
.AutoBind(true)
.Sortable()
.EnableCustomBinding(true)
)
<div class="pull-right">
<button type="submit" id="Apply" class="submitbtn" style="border: 0px none;"><i class="greenbtn"></i>@GlobalResourceHelper.GetGlobalResource(ResourceFiles.ButtonsResources, "BTN_APPLY")</button>
</div>
}
我的控制器:
public ActionResult Apply(ResourceViewModel ApprovalList)
{
// I'm not getting Checkbox Checked or not in ApprovalList
}
【问题讨论】:
-
您的复选框甚至没有名称属性,因此它们不会回发(以及由于重复的 id 而导致的无效 html)
-
@Stephen 我已经更改了 ID 并添加了一个名称属性,然后值也没有保留,我已经编辑了我的代码
-
你是通过 ajax 发帖吗?
-
您的 html 仍然无效(每一行都有一个带有
id=checkbox的复选框)所以摆脱 id 的。现在您有很多带有name="remember"的复选框,它们与ResourceViewModel无关(您可以检查Request.Form以查看发回的内容)但是由于未选中的复选框不会发回,因此无法匹配哪个行是否已“检查”。 -
@Ankush :不,我没有使用 Ajax
标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 kendo-ui kendo-grid