我在我的MVC2項目的視圖中使用複選框,以允許用戶選擇多個對象。這是我認爲的代碼(跳過無關行:從mvc 2視圖中的複選框返回數據
<h2>Install New Equipment</h2>
//Html.BeginForm("CreateRequest1", "Home", FormMethod.Post);
<div>Employee's First Name: <%= Model.Employee.EmpFName%></div>
<div>Employee's Last Name: <%= Model.Employee.EmpLName%></div>
<div>Employee's Phone Number: <%= Model.Employee.Phone%> </div>
<br />
<div>Please select the equipment you would like to request:</div><br />
<div> <% foreach (var info in ViewData.Model.EquipDescription)
{ %>
<% = Html.CheckBox("Description", info.ID) %><%=info.Description%> <br />
<%} %>
</div><br />
<div>Please Select the Location for the Equipment to be Installed </div><br />
<div>Building <%= Html.DropDownList("NewBuildings", new SelectList((IEnumerable)ViewData["buildings"], "ID", "Buildings")) %>
Floor <%= Html.DropDownList("NewFloors", new SelectList((IEnumerable)ViewData["floors"], "ID", "FloorNumber")) %>
Office<%= Html.DropDownList("NewOffices", new SelectList((IEnumerable)ViewData["offices"], "ID", "OfficeNumber")) %>
</div>
<br />
<div>Comments: <%=Html.TextArea("Comments") %></div><br />
<%Html.EndForm();%> (我刪除了<%%>
各地開始表格線,所以我的整個後會顯示) 一切都在視圖完美顯示。我收到來自用戶的所有其他數據。我只是不知道如何從選定的複選框
[HttpPost]
public ActionResult CreateRequest1(int NewBuildings, int NewFloors, int NewOffices, string comments, int[] Description)
我應該在這裏補充來獲得選擇的值收到的數據?
我改變視圖控制器方法入手[HttpPost]公衆的ActionResult CreateRequest1(INT新船,詮釋NewFloors,詮釋NewOffices,串意見,ICollection的說明)和ICollection的說明仍爲空 –
user695916
2011-04-16 20:24:21
我也在集合方法中嘗試了ICollection說明,它也是空的。我的複選框是否正確創建? –
user695916
2011-04-16 20:31:06
有人請幫助我我已經嘗試了所有我能想到的即使int []說明,我一直在使用谷歌和嘗試每一個我能找到的例子。我確定我錯過了一些簡單的東西,但我不知道什麼或在哪裏再看看 – user695916 2011-04-16 20:44:00