javascript - why webgrid always pass default -
i make editable webgrid, when pass value webgrid, allways give default value checkbox. when value in database "true", after edited checkbox false, value pass "true" seams value in database. can 1 me
this view
<div> @{ var grid = new webgrid(model.datadirilist, rowsperpage: 15, canpage: true, cansort: true, ajaxupdatecontainerid: "gridcontent"); @grid.gethtml( tablestyle: "row", alternatingrowstyle: "alt", columns: grid.columns( grid.column("id", format: @<text> <span class="display-mode">@item.id </span> <label id="userid" class="edit-mode">@item.id</label> </text>, style: "col1width" ), grid.column("nama", "nama", format: @<text> <span class="display-mode"> <label id="lblnama" >@item.nama</label> </span> <input type="text" id="nama" value="@item.nama" class="edit-mode" /></text>, style: "col2width"), grid.column("umur", "umur", format: @<text> <span class="display-mode"> <label id="lblumur" >@item.umur</label> </span> <input type="text" id="umur" value="@item.umur" class="edit-mode" /></text>, style: "col2width"), grid.column(header: "active", format:@<text> <span class="display-mode"> @html.raw("<input type=\"checkbox\" " + ((item.active == true) ? "checked='cheked'" : "") + "disabled = 'disabled'/>") </span> <input id="chkactive" type="checkbox" @(item.active ? " checked=checked" : null) name="closeselling" value="@item.active" class="edit-mode" /></text>, style: "col2width"), grid.column("action", format: @<text> <button class="edit-user display-mode" >edit</button> <button class="save-user edit-mode" >save</button> <button class="cancel-user edit-mode" >cancel</button> </text>, style: "col3width" , cansort: false) )); } </div> @section scripts { <script type="text/javascript"> $(document).ready(function () { $('.edit-mode').hide(); $('.edit-user, .cancel-user').on('click', function () { var tr = $(this).parents('tr:first'); tr.find('.edit-mode, .display-mode').toggle(); }); $(".save-user").on("click", function () { var tr = $(this).parent().parent(); var t = tr.find("#nama").val(); var umur = tr.find('#umur').val(); var id = tr.find('#userid').html(); var chkactive = tr.find('#chkactive').val(); $.ajax({ url: '@url.action("updateuser", "home")', type: "post", data: { customernameid: t, userid: id, umur: umur,active: chkactive}, datatype: 'json', success: function (result) { $("#mygrid").html(''); $("#mygrid").html(result); } }); tr.find("#lblnama").text(t); tr.find("#lblumur").text(umur); tr.find('.edit-mode, .display-mode').toggle(); }); }); </script> }
my controller
public jsonresult updateuser(string customernameid, string userid, string umur, bool active) { var id = convert.toint32(userid); var intumur = convert.toint32(umur); var dd = db.datadiris.asqueryable().where(r => r.id == id).single(); dd.id = id; dd.nama = customernameid; dd.umur = intumur; db.entry(dd).state = entitystate.modified; db.savechanges(); string message = "success"; return json(message, jsonrequestbehavior.allowget); }
Comments
Post a Comment