2011-04-16 54 views
0

我在我的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) 

我應該在這裏補充來獲得選擇的值收到的數據?

+0

我改變視圖控制器方法入手[HttpPost]公衆的ActionResult CreateRequest1(INT新船,詮釋NewFloors,詮釋NewOffices,串意見,ICollection的說明)和ICollection的說明仍爲空 – user695916 2011-04-16 20:24:21

+0

我也在集合方法中嘗試了ICollection 說明,它也是空的。我的複選框是否正確創建? – user695916 2011-04-16 20:31:06

+0

有人請幫助我我已經嘗試了所有我能想到的即使int []說明,我一直在使用谷歌和嘗試每一個我能找到的例子。我確定我錯過了一些簡單的東西,但我不知道什麼或在哪裏再看看 – user695916 2011-04-16 20:44:00

回答

0

你需要一個參數添加到您的方法,如: [HttpPost] 公衆的ActionResult CreateRequest1(INT新船,詮釋NewFloors,詮釋NewOffices,串意見,ICollection的說明)

我認爲你的價值是int,但可以根據需要更改它。

你可以在這裏閱讀更多: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

+0

我改變了我的[HttpPost] public ActionResult CreateRequest1(int NewBuildings,int NewFloors,int NewOffices,string comments,ICollection ) { – user695916 2011-04-16 20:21:20

+0

我改變視圖控制器方法來啓動與[HttpPost] 公共的ActionResult CreateRequest1(INT新船,INT NewFloors,INT NewOffices,串註釋,ICollection的描述) 和ICollection的說明仍然是空的 和 – user695916 2011-04-16 20:23:19

+0

我也嘗試ICollection 描述結束它也是空的 – user695916 2011-04-16 20:29:49