jquery - Send HTML Element Text From View To Controller -


i call function on controller view : (when user press button)

  <input id="deactive_btn" type="button" value="deactive" class="btn btn-default" onclick="location.href='@url.action("setactive", "home", new { email = ??? ,activestatus = ???  })'"/> 

the purpse of button is:

i have list of user display admin, admin allow deactivate user(the admin can achive pressing button "deactivate")

now need send "setactive" function in controller email of user can him , deactivate user, email of user display in td in table of users, gave id how can value it(from html element) , place here:

@url.action("setactive", "home", new { email = here! 

this complete code of list user :

foreach (appuser appuser in userlist) {     <tr>         <td width="15%">@appuser.name</td>         <td class="text-left" width="15%">@appuser.date.substring(0, appuser.date.indexof(" "))</td>         <td class="text-left" width="10%">@appuser.role</td>         <td id="user_email" class="text-left" width="24%">@appuser.email</td>         <td class="text-left" width="10%"><span id=@url.content("status_lbl" + index) class="label label-success">active</span></td>         <td class="btn-group-sm text-center">             <input id="@url.content("freeze_btn" + index)" type="button" value="deactivate" class="btn btn-default" onclick="location.href='@url.action("setactive", "home", new { email =  ,activestatus = html  })' "  />             <input type="button" value="edit" class="btn btn-default " />             <input type="button" value="delete" class="btn btn-default " />         </td>     </tr>     index++; } 

and jquery script :

$('input[id^=freeze_btn]').click(function (event) {     var btn = $(event.target);     var text = $(this).attr('value');     var newid = $(this).attr('id').replace('freeze_btn', 'status_lbl');     if (text == "active") {         btn.val("deactivate");         $('#' + newid).removeclass("label-danger").addclass("label-success").text("active");     }     if (text == "deactivate") {         btn.val("active");         $('#' + newid).removeclass("label-success").addclass("label-danger").text("unactive");     } }); 

i think can using form there other way?

there motivation ajax form on html form?

since each row has own button, you're fine. can use razor set value in html attributes:

<input onclick="location.href='@url.action("setactive", "home",      new { email = appuser.email.id ,activestatus = html  })' "  /> 

i've removed of code make easier read.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -