MVC checkbox event in grid
I am a new bee in MVC world. I have a scenario like, i have an grid with a checkboxs as one column. When i click on checkbox an event would fire and it would update some values in database. I am using Razor engine.
<table>
<tr>
<th>
ID
</th>
<th>
PName
</th>
<th>
PDescription
</th>
<th>
PSerialNo
</th>
<th>
PPrice
</th>
<th>
PActive
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.ID
</td>
<td>
@Html.ActionLink(@item.PName, "Edit", new { id = @item.ID })
</td>
<td>
@item.PDescription
</td>
<td>
@it开发者_Go百科em.PSerialNo
</td>
<td>
@String.Format("{0:c}", item.PPrice)
</td>
<td>
@Html.CheckBox("chkActiveItem", item.PActive)
</td>
</tr>
}
here the content is showed in the grid. Here when i click on this check box i want to update the flag in the database. How will i do it? Please help.
foreach doesn't work in this case. You need to use for loop and then changes will get picked up on server side on post.
if you want to do ajax call then simply store id of each item within its row and pass that as parameter during ajax call to identify checked item on server side.
精彩评论