2014-09-22 3 views
0

컨트롤러에 점검 된 행의 테이블 행 값을 제출하고 싶습니다. 내 컨트롤러는 항상 null 값의 매개 변수를받습니다.컨트롤러에 양식 데이터 게시

@model IEnumerable<GoogleMapsAPIWeb.Models.Schedule> 
@using (Html.BeginForm("Route", "Home", FormMethod.Post)) 
{ 
    <div> 
     <table id="schedulerTable"> 
      <thead> 
       <tr> 
        <th scope="col"></th> 
        <th scope="col" >View</th> 
        <th scope="col">Site Id</th> 
       </tr> 
      </thead> 
      <tbody> 
       @foreach (var row in Model) 
           { 
            <tr> 
             <td>@Html.CheckBoxFor(c=>row.isSelected)</td> 
             <td class="smallerDataField"> 
              <a>View</a>@*TODO add code to view*@ 
             </td> 
             <td><div class="smallerDataField">@row.SiteId</div></td> 
            </tr> 
           } 
      </tbody> 
     </table> 
     <input id="btnFindRoute" type="submit" value="Plan Route" /> 
    </div> 
} 


[HttpPost] 
public ActionResult Route(IEnumerable<Schedule> Schedules) 
{ 
+0

상자를 선택한 다음 제출하면 null이 반환됩니까? – jwatts1980

+0

네, 그렇습니다. . . – user1152145

+0

@ Html.CheckBoxFor (c => row.isSelected)'에 의해 생성 된 HTML 코드 스 니펫을 게시 할 수 있습니까? – jwatts1980

답변

1

for 루프를 사용하십시오. More info

for (int i = 0; i < Model.Count(); i++) 
{ 
<tr> 
<td>@Html.CheckBoxFor(c=> Model[i].isSelected)</td> 
</tr> 
... 
} 
+0

OP는 이미'foreach'를 사용하고 있습니다. – jwatts1980

+1

추가 정보를 제공해 주셔서 감사합니다. 알고있는 것이 좋다! MVC에서 아직이 작업을 수행하지 않아도됩니다. 컴파일러가 이름에 대해 다른 HTML을 생성한다는 것을 알지 못했습니다. – jwatts1980