Here is my HTML code snippet:
<table>
<tr>
<td>
@Html.DropDownList("Statues", (SelectList)ViewBag.UserType, string.Empty, new { @class = "NewIDCn",@id = "name1" })
</td>
<td>
<a class = "UpdateU" href="@Url.Action("Update", "UserPromoted", new { id = item.UserID})">Update</a>
</td>
</tr>
<tr>
<td>
@Html.DropDownList("Statues", (SelectList)ViewBag.UserType, string.Empty, new { @class = "NewIDCn",@id = "name2" })
</td>
<td>
<a class = "UpdateU" href="@Url.Action("Update", "UserPromoted", new { id = item.UserID})">Update</a>
</td>
</tr>
</table>
And below is the included script block with JavaScript:
<script type="text/jscript">
$(document).ready(function () {
var i = 0;
$('.NewIDCn').each(function () {
i++;
var newID = 'name' + i;
$(this).attr('id', newID);
$(this).val(i);
});
});
$(function () {
$('.UpdateU').click(function () {
var name = $('#name').val();
this.href = this.href + '?UserType=' + encodeURIComponent(name);
});
});
</script>
Also, here is a glimpse at my Controller function:
public ActionResult Update(string id, string UserType)
{
query = "UPDATE tblUserRegister SET UserType = ' " + UserType + "' WHERE (UserID = '" + id + "')";
cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
}
The document.ready
function aims to dynamically increment the ID of elements named name(name1,name2)
.
When I trigger the URL action, the statue ID should be updated to reflect the User Type. How can I ensure that this happens correctly and return both the ID name and User Type to the controller for processing?