0

I want to submit the table row values of the rows that are checked to my controller. My controller is always receiving a parameter of value 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) { 
4
  • Does it return null if you check the box and then submit? Commented Sep 22, 2014 at 20:30
  • Can you post the code snippet of the HTML that is generated by <td>@Html.CheckBoxFor(c=>row.isSelected)</td>? Commented Sep 22, 2014 at 20:42
  • <td><input id="row_isSelected" name="row.isSelected" type="checkbox" value="true" /><input name="row.isSelected" type="hidden" value="false" /></td> Commented Sep 22, 2014 at 20:47
  • Have you tried @awesome's solution yet? Commented Sep 22, 2014 at 20:48

1 Answer 1

1

Use for loop for this purpose. More info

for (int i = 0; i < Model.Count(); i++) { <tr> <td>@Html.CheckBoxFor(c=> Model[i].isSelected)</td> </tr> ... } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the additional info. That's nice to know! Haven't had to do this in MVC yet. I didn't realize the compiler generated different HTML for the names.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.