c# - Change Button on-click only if data is successfully stored to database without postback asp.net mvc5 EF6 -


change button without post-back after storing data successfully

i have situation wherein have change button "send request" "request sent". there 'n' number of such buttons in form , need change buttons of them

the button should change if data stored database without reloading form. , here how have stored data database.

public actionresult sendrequest(string requestid) {         myrequest request = new myrequest();         request.userid = loggedinuserid;         request.futurefriendid = requestid;         request.status = requeststatus.pending;         db.myrequests.add(request);         db.savechanges();         return view(); } 

later might want change button "request sent" "cancel request" rollback operation. please give me solution same. thank you!

i return bool instead actionresult. js (jquery) code should this:

$(btn).click(function(){ $(btn).attr("disabled", "disabled").val("sending request..."); $.ajax({             url: '/yoururl',             type: 'get',             data: { requestid: '12345' },             async: true,             success: function(returnparameters) {                 $(btn).attr("disabled", "disabled").val("request sent");             },             error: function(jqxhr, textstatus, errorthrown) { $(btn).removeattr("disabled").val("send request"); // error, reset.             }         }); }); 

this give 3 situations button:

  1. sending
  2. sent
  3. normal

i've set button "disabled" prevent more clicks incase in progress/the request sent.


Comments