0

I'm new in MVC5 and i don't know much about dealing with view controls . I create an MVC project , but I need to get the data of checked Rows when submit in the controller , Please can anyone help me ??

this is my view code for the table

<table class="table" id="Table_Session">
    <tr>
        <th>
            <label> &nbsp;</label>
        </th>
        <th>
            <label>User Id</label>
        </th>
        <th>
            <label>IP Address</label>
        </th>
        <th>
            <label>Licence Type</label>
        </th>
        <th>
            <label>Login Date</label>
        </th>
        <th>
            <label>Login Time</label>
        </th>
        <th></th>
    </tr>

    @For Each item In Model
        @<tr>
            <td>
                @If Not IsNothing(item) Then
                    @Html.Hidden("SessionID", item.SessionID)
                    @<input type="checkbox" id="chboxRow" value="item.SessionID" onclick="">
                End If
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.sUserId)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.IpAddress)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.licencetype)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.LoginDate)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.Logintime)
            </td>
        </tr>
    Next



</table>
<div>
    @Using Html.BeginForm("KillSession", "KillSession", FormMethod.Post)
              @<input type="submit"
                class="btn btn-default btn-xs"
                value="Kill Session" />
    End Using
    @Using Html.BeginForm("s_Continue", "KillSession")
                @<input type="submit"
                class="btn btn-default btn-xs"
                value="s_Continue" />
    End Using
</div>
tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

-1

So you need to wrap all of the checkboxes in the form or the data will not be included when you post the form. Try this as a stating place.

@Using Html.BeginForm("KillSession", "KillSession", FormMethod.Post)

<table class="table" id="Table_Session">
    <tr>
        <th>
            <label> &nbsp;</label>
        </th>
        <th>
            <label>User Id</label>
        </th>
        <th>
            <label>IP Address</label>
        </th>
        <th>
            <label>Licence Type</label>
        </th>
        <th>
            <label>Login Date</label>
        </th>
        <th>
            <label>Login Time</label>
        </th>
        <th></th>
    </tr>

    @For Each item In Model
        @<tr>
            <td>
                @If Not IsNothing(item) Then
                    @Html.Hidden("SessionID", item.SessionID)
                    @<input type="checkbox" id="chboxRow" value="item.SessionID" onclick="">
                End If
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.sUserId)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.IpAddress)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.licencetype)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.LoginDate)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.Logintime)
            </td>
        </tr>
    Next

</table>

@<input type="submit" class="btn btn-default btn-xs" value="Kill Session" />
End Using

Then maybe read this and do some Googling, the answers to this are out there, over and over and over again!

Community
  • 1
  • 1
matt_lethargic
  • 2,706
  • 1
  • 18
  • 33
  • thank u matt_lethargic for your help but it doesn't work , it always return the value of the first session , not the checked sessions ,,, – user3703119 Jun 04 '14 at 06:02
  • As i said this was a STARTING POINT to show you that you needed to wrap all of the check boxes in the form, not 100% working version. Did you read the link I also included? This is a similar question that has already been answered and should give you all the information needed. – matt_lethargic Jun 04 '14 at 07:55