Update record in HTML Table using ActionLink in ASP.Net MVC

Last Reply 11 months ago By dharmendr

Posted 11 months ago

hi I listed the value from database and I want to update password filed after listed , my scenario like below

        <table id="myTable" class="table table-striped table-bordered table-condensed">
                    <th style="width: 2px">Id</th>                    
                    <th>Name And Surname</th>
                @foreach (var veri in Model)
                    <td>@Html.TextBoxFor(t => new AccountInfo().Pwd, new { @Value = @veri.Pwd, @class = "form-control", style = "width:100px"})
                      @Html.ActionLink(linkText: "UPDATE", actionName: "UpdateManageUser", controllerName: "AdminPanel", routeValues: new {id = @veri.Id, NewPwd = @veri.NewPwd },
                      htmlAttributes: new {onclick= "userUpdateJson()", id = "btnUpdate",@class = "btn btn-primary pull-left"})


        public ActionResult UpdateManageUser(int id,string pwd)
            var con = Core.GetLocalConnection();

            var cmd = new SqlCommand("SELECT COUNT(*) FROM S_ACCOUNTINFO WHERE ID=@P1", con);
            cmd.Parameters.AddWithValue("@P1", id);
            var sonuc = Convert.ToInt32(cmd.ExecuteScalar());
            if (sonuc == 1)
                cmd = new SqlCommand("UPDATE S_ACCOUNTINFO SET PWD=@P2 WHERE ID=@P1", con);
                cmd.Parameters.AddWithValue("@P1", id);
                cmd.Parameters.AddWithValue("@P2", pwd);

            return RedirectToAction("ManageUser");


You are viewing reply posted by: dharmendr 11 months ago.
Posted 11 months ago
alya14 says:
var Id = $(this).closest('tr').find('td').eq(0).html().trim();

 Change the above line with 

var id = $(this).closest('tr').find('#Id').val();

and assign id property to the textbox like below.

<td>@Html.TextBoxFor(i => customer.Id, new { id = "Id", style = "width:100%" })</td>