Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have some collection names, each collection has read, write options
so I am displaying these options in front of collection as check boxes depends on checkbox checked property

Here I am not able to Pass checkbox values from view to Mvc Action method on HTML.Action Link

Kindly advice

What I have tried:

<table id="assets-data-table" class="table table-striped table-bordered"
         style="margin-left:800px;margin-top:-10px;width:500px;">
      <tr>

          <th>Collection Name</th>
          <th>C</th>
          <th>CA</th>
          <th>M</th>
          <th>R</th>
          <th></th>
      </tr>

      @foreach (var item in Model)
      {
          <tr>
              <td style="white-space:nowrap;">
                  @Html.DisplayFor(modelItem => item.CollectionName)
              </td>
             @foreach (var CollectionRole in item.CollRole)
             {
                 if (CollectionRole.Role == "Copy")
                 {
                  @*<td>@CollectionRole.CollectionRole</td>*@
                  <td>@Html.CheckBoxFor(modelItem => CollectionRole.Checked)</td>
                 }
                 if (CollectionRole.Role == "Author")
                 {
                  <td>@Html.CheckBoxFor(modelItem => CollectionRole.Checked)</td>
                 }
                 if (CollectionRole.Role == "Reader")
                 {
                  <td>@Html.CheckBoxFor(modelItem => CollectionRole.Checked)</td>
                 }
                 if (CollectionRole.Role == "writer")
                 {
                  <td>@Html.CheckBoxFor(modelItem => CollectionRole.Checked)</td>
                 }

             }
              <td>

                  @Html.ActionLink("SaveChanges", "AddUserToGroup", new { id = item.ID, CollectionName = item.CollectionName,coll = item }, new { @class = "lnkDetail" })

              </td>
          </tr>
      }

  </table>
Posted
Updated 8-Jan-19 18:38pm
v2
Comments
j snooze 8-Jan-19 17:50pm    
I'm not sure you can pass a collection in an action link because essentially its creating a query string(I think) you may have to post the data to the new page instead and then from the post method on the new page/controller, save your changes, and display the data or whatever it is you're trying to do.

1 solution

THe first thing is you have to design ur entity in such a way that you can get the values posted.
And you can use :

                  @Html.ActionLink("SaveChanges", "AddUserToGroup", new { id = item.ID, CollectionName = item.CollectionName,coll = item,model=modelWithCheckedValues }, new { @class = "lnkDetail" })


This is just a eg.

so while posting the data you can get that checkbox values in your post action method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900