我想在我的视图中从复选框中返回一个Personnes列表,并在我的控制器中获取它,但selectedObjects count始终为0 ...
这是我的复选框视图:
--SET VARIABLE FOR A REGISTRATION MARK
DECLARE @Reg nvarchar(10);
SET @Reg = 'PH-BGO';
--SET VARIABLE FOR MANUFACTURER OF REGISTRATION MARK
DECLARE @Manufacturer nvarchar(100);
SET @Manufacturer = (SELECT FleetInfoKLM.Manufacturer FROM FleetInfoKLM WHERE FleetInfoKLM.Reg = @Reg);
--SET VARIABLE FOR FAMILY OF REGISTRATION MARK
DECLARE @Family nvarchar(100);
SET @Family = (SELECT FleetInfoKLM.Family FROM FleetInfoKLM WHERE FleetInfoKLM.Reg = @Reg);
--SET VARIABLE FOR SERIES OF REGISTRATION MARK
DECLARE @Series nvarchar(100);
SET @Series = (SELECT FleetInfoKLM.Series FROM FleetInfoKLM WHERE FleetInfoKLM.Reg = @Reg);
--SHOW LOCAL VARIABLES VALUES
SELECT @Manufacturer;
SELECT @Family;
SELECT @Series;
--SELECT MAINTENANCE DOCUMENTS BASED ON VARIABLES FOR MANUFACTURER, FAMILY AND SERIES
SELECT MaintenanceDocumentation.name FROM MaintenanceDocumentation
WHERE MaintenanceDocumentation.path_locator IS NOT NULL
AND CONTAINS(file_stream, @Manufacturer)
AND CONTAINS(file_stream, @Family)
AND CONTAINS(file_stream, @Series);
我的控制员:
@using (Html.BeginForm("Presence", "Evenement"))
{
foreach (var p in Model.Personnes)
{
<input type="checkbox" name="selectedObjects" value="@p" />
}
@Html.AntiForgeryToken()
<input type="submit" value="Valider Presence" class="btn btn-primary" />
}
答案 0 :(得分:0)
您无法将复选框绑定到复杂对象。复选框仅回发单个值。相反,您需要绑定到Personne
的属性,例如,如果它具有属性int ID
,那么
foreach (var p in Model.Personnes)
{
<input type="checkbox" name="selectedObjects" value="@p.ID" />
}
然后将POST方法签名更改为
public ActionResult Presence(int[] selectedObjects)