I have a view-model which has a data grid like the one shown below
<table>
@foreach (var item in Model)
//for(int i=0;i<Model.Count();i++)
{
using (Html.BeginForm("Edit", "Views", FormMethod.Post))
{
<tr>
<td>
@Html.TextBoxFor(modelItem => item.Description, new { id = "description" })
</td>
<td>
@Html.DisplayFor(modelItem => item.DisplayAt, new { id = "displayat" })
</td>
<td>
@Html.DropDownListFor(m => item.selectedRegion, item.RegionsList, item.Region, new { id = "ddlregion" })
</td>
<td>
@Html.DropDownListFor(modelItem => item.Products, item.ProductsList, item.Products, new { id = "ddlproduct" })
</td>
<td>
@Html.DropDownListFor(modelItem => item.Companies, item.CompaniesList, item.Companies, new { id = "ddlcompany" })
</td>
<td>
@Html.DropDownListFor(modelItem => item.UserName, item.UserNamesList, item.UserName, new { id = "ddlusers" })
</td>
<td>
@Html.CheckBoxFor(modelItem => item.Visible, new { id = "chkVisible" })
</td>
<td>
<input type="submit" value="Edit" id="button" />
</td>
</tr>
}
}
</table>
I have written a jquery function to work on the click of the button with id=button
However, it works only for the first row. When I click on the buttons from the second row the function is not being called. How do I write a jquery which will be called when any of the buttons is clicked.
My jQuery code:
$('#button').click(function () {
var product = $("#ddlproduct").find("option:selected").text();
var user = $("#ddlusers").find("option:selected").text();
*does something*
});
This is being called only for the first row. I'm assuming there is something like a foreach button with id that is clicked.