Ok, I’m an MVC newbie coming from a webforms background, so please excuse any ignorance here. Here is my scenario. I’ve got a table consisting of a list of applications and associated permissions. Each table row consists of 3 pieces of information: a checkbox, some text describing the row, and a dropdown list allowing the user to select the appropriate permission for the application. I want to post this data and only work with the rows in the table which were checked (the id of the row is embedded as the checkbox name). From there, I want to grab the selected value from the DropDownList, and call the necessary code to update the DB. Here is my View page’s code:
<%foreach (var app in newApps) { %> <tr> <td><input type='checkbox' name='AddApps' value='<%=app.ApplicationId %>' /></td> <td><%=Html.Encode(app.ApplicationName)%></td> <td><%=Html.DropDownList('AppRole', new SelectList(app.Roles, 'RoleId', 'RoleDescription'))%></td> </tr> <%} %>
How would I retrieve the appropriate values from the FormCollection when I get to the controller on form post? I have done this in the past when I only had checkbox values to retrieve by just calling Request.Form[‘CheckBoxName’] and parsing the string.
Or am I going about this entirely wrong?
You are halfway right in order to post your data that the controller can read the info it must be inside a form as so :
and on your controller :
This site gives more details on how to handle the dropdownlist helper:
http://quickstarts.asp.net/previews/mvc/mvc_HowToRenderFormUsingHtmlHelpers.htm