gpt4 book ai didi

asp.net-mvc - MVC 2 - 无法检索 MVCContrib 网格中的复选框值

转载 作者:行者123 更新时间:2023-12-01 14:01:17 25 4
gpt4 key购买 nike

我的 MVC Contrib 网格上有一个复选框;

        <%= Html.Grid(Model.TeamMembers).Columns(column =>
{
column.For(model => model.Surname);
column.For(model => model.Forename);
column.For(model => model.DaysLeftThisYear).Named("Days Left This Year");
column.For(model => model.DaysLeftNextYear).Named("Days Left Next Year");
column.For(model => Html.CheckBox("chkbox", model.SelectForConfirmationFlag))
.Named("Select?")
.Sortable(false);
}).Sort((GridSortOptions)ViewData["sort"]) %>
</div>
<p><%= Html.Pager((IPagination)Model.TeamMembers)%></p>

然后用户可以单击复选框,但是当他提交时, Controller 中不会选取新值。该页面包含在具有 BeginForm 语句的页面中;

<% using (Html.BeginForm("Home", "Approver", FormMethod.Post, new { id = "frmHome" }))
{%>

我的 Controller 看起来像;

[HttpGet]
[Authorize(Roles = "Administrator, ManagerIT, ManagerAccounts, Approver")]
public ActionResult Home(GridSortOptions sort, int? page)
{
SessionObjects.LoggedInUserName = User.Identity.Name;
if (SessionObjects.ApprovalViewModel.TeamMembers.Count() == 0)
SessionObjects.ApprovalViewModel = new ApprovalViewModel();
TempData["ReadOnly"] = true;
if (sort.Column != null)
{
SessionObjects.ApprovalViewModel.TeamMembers = SessionObjects.ApprovalViewModel.TeamMembers.OrderBy(sort.Column, sort.Direction);
}
SessionObjects.ApprovalViewModel.TeamMembers =
SessionObjects.ApprovalViewModel.TeamMembers.AsPagination(page ?? 1, Utility.GetPageLength());
ViewData["sort"] = sort;
return View(SessionObjects.ApprovalViewModel);
}

[HttpPost]
public ActionResult Home(ApprovalViewModel avm)
{
if (avm.TeamMembers.Count() == 0)
{
TempData["ErrorMessage"] = "You have no team members to select";
return RedirectToAction("Home");
}
else if (avm.TeamMembers.Where(x => x.SelectForConfirmationFlag == true).Count() == 0)
{
TempData["ErrorMessage"] = "You must select at least one team member";
return RedirectToAction("Home");
}
else
{
string[] selectedEmployees = avm.TeamMembers
.Where(x => x.SelectForConfirmationFlag == true)
.Select(x => x.EmployeeId.ToString()).ToArray();
var result = RedirectToAction("ConfirmBookings", "Approver",
new { selectedEmployeesParameters = selectedEmployees });
result.AddArraysToRouteValues();
return result;
}
}

最佳答案

您不应该匹配复选框的名称属性吗?您的下一行不会生成名称为 SelectForConfirmationFlag

的复选框
column.For(model => Html.CheckBox("chkbox", model.SelectForConfirmationFlag))

你可以尝试跟随吗?

column.For(model => Html.CheckBoxFor(m => m.SelectForConfirmationFlag))

或者

column.For(model => Html.CheckBox("SelectForConfirmationFlag",model.SelectForConfirmationFlag))

关于asp.net-mvc - MVC 2 - 无法检索 MVCContrib 网格中的复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7612254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com