asp.net - Dynamically creating array of objects in view -


i outputting data query , placing input box each 1 on view.

this partial view inside 1 of forms.

@model ienumerable<project.models.vehicletypeseat> @using pagedlist.mvc; <link href="~/content/pagedlist.css" rel="stylesheet" type="text/css" /> @{     int counter = 0; } <p>  </p>       <table>         <tr>             <th>                 <div class="editor-field">                     crew                 </div>             </th>             <th>                 description             </th>          </tr> @{      @for (var item in model)     {             <tr>                 <input type="hidden" name="raceseats.index" value="@(counter)" />                 <td>                     @html.dropdownlist(item.crewid, null, "--select crew member--", htmlattributes: new { @class = "form-control", @name = "raceseats["+@counter+"].personid" })                 </td>                  <td>     @html.displayfor(modelitem => item.vehicletypeseatdescription) </td>                </tr>             counter += 1;         }      </table> } 

i trying accomplish kind of thing read array post:

<input type="hidden" name="people.index" value="0" /> <input type="text" name="people[0].firstname" /> <input type="text" name="people[0].lastname" /> 

the problem having trouble manipulating names of "displayfor" , "dropdownlist"

i'm not sure understand question, have found when want bind model foreach can cause problems. instead try

@for (int = 0; < model.count(); i++) {     // reference each item index     @html.dropdownlistfor(model[i].crewid,         null, "--select crew member--", htmlattributes: new { @class = "form-control"})  }   

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -