c# - Button in partialview stops working after search -
i have layout page , partialview.
i have search-button on layout page , update-button in table in partial view.
once click search-button update-button stops working. works fine until search. i'm guessing has forms , actionresult can't work. actionresult never reached - "nothing" happens.
controller - registertruckuser
[httppost] public actionresult registertruckuser(string registername, string registerpassword, string employeenumber, string userteam) { var model = new registermodel { userlist = db.searchtruckusers(""), userteamlist = getuserteamlist(), triggeronload = true }; //if save button clicked user updated if (request.form.allkeys.contains("btnupdateuser")) { if (!request["btnupdateuser"].isempty()) { name = request.form["item.name"]; password = request["item.password"]; employeenumber = request["item.employeenumber"]; userteam = request["item.userteam"]; db.updatetruckuser(name, password, employeenumber, userteam); model.userlist = db.searchtruckusers(""); return partialview(model); } } modelstate.clear(); return view(model); } model.triggeronloadmessage = errormessage; return view(model); }
controller - searchpartialview
[httppost] public partialviewresult searchpartialview(string searchuserstring) { if (session["myid"] == null) { expiresession(); } if (!modelstate.isvalid) redirecttologin(); if (searchuserstring.any(char.isdigit)) { var model1 = new registermodel { triggeronload = false, userlist = db.searchtruckusersempnum(searchuserstring), userteamlist = getuserteamlist() }; return partialview("_registertruckuserpartialview", model1); } var model = new registermodel { triggeronload = false, userlist = db.searchtruckusers(searchuserstring), userteamlist = getuserteamlist() }; return partialview("_registertruckuserpartialview", model); }
registerlayout
@model name.models.registermodel <!doctype html> <html lang="en"> <head> <title>@viewbag.title - register</title> @scripts.render("~/scripts/jquery.unobtrusive-ajax.min.js") </head> <body> @renderpage("~/views/shared/_header.cshtml") @renderbody() <div class="center" id="top"> <div id="search" class="active"> <h1>manage users</h1> @using (ajax.beginform("searchpartialview", "register", null, new ajaxoptions { httpmethod = "post", insertionmode = insertionmode.replace, updatetargetid = "divusers", }, new { id = "usertable" })) { @html.textbox("searchuserstring", null, new { @class = "responsivetextbox", @placeholder = "search username or employment number" }) <p> <input type="submit" class="standardbutton logsearch" name="submit" value="search" /> </p> } <div id="divusers"> @{html.renderpartial("_registertruckuserpartialview");} </div> </div> </div> @renderpage("~/views/shared/_footer.cshtml") </body> </html>
partialview (table)
<table class="centeredtable"> <thead> <tr> <th>name</th> <th>password</th> <th>employment number</th> <th>team</th> <th></th> </tr> </thead> <tbody> @foreach (var item in model.userlist) { using (html.beginform()) { <tr id="usertabletr1"> <td id="usertabletd1"> @html.editorfor(modelitem => item.name, new {htmlattributes = new {@name = "test1", @style = "border: 0px none;"}}) </td> <td id="usertabletd1"> @html.editorfor(modelitem => item.password, new {htmlattributes = new {@name = "registerpassword", @type = "password", @style = "border: 0px none; "}}) </td> <td id="usertabletd1"> @html.editorfor(modelitem => item.employeenumber, new {htmlattributes = new {@name = "employeenumber", @readonly = "readonly", @style = "border: 0px none; background: white;"}}) </td> <td id="usertabletd1"> @html.dropdownlistfor(modelitem => item.userteam, model.userteamlist, item.userteam, new {htmlattributes = new {@name = "team", @style = "border: 0px none;"}}) </td> <td id="usertabletd1"> <input class="standardbutton adddefaultvaluesubmit" type="image" src="~/pictures/saveicon.ico" alt="save" value="save" name="btnupdateuser"/> <input class="standardbutton adddefaultvaluesubmit" type="image" src="~/pictures/trashcanicon.ico" alt="delete" value="delete" name="btndeleteuser"/> </td> </tr> } } </tbody> </table>
in partial view should this.
<input type="button" value="confirm team change" class="btnconfirm"/>
and add "main" layout.
$(document).on('click', '.btnconfirm', function(){ $.ajax({ url: '@url.action("registertruckuser", "register")', type: 'post', cache: false, async: true, data: $('form').serialize(), success: function(result){ //do } }); });
Comments
Post a Comment