I need to pass a value from the front end to the controller, I'm struggling to get it to pass the value.
Ajax/Jquery
//unlock user account
$("#results").on('click', ".unlockactionbutton", function (e) {
e.preventDefault();
var userid = this.getAttribute("userid");
if (envdd.children(':selected').val() == "") {
alert("Please select User");
} else {
alert(userid);
$.ajax({
type: "GET",
url: "@Url.Action("UnlockUser", "Home", new { userid = userid })",
//Url.Action("UnlockUser", "Home", new { id = userid });
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(userid),
success: function (data) {
console.log(data);
},
error: function(data) {
alert('error');
console.log(data);
}
});
}
});
Here is the ActionResult. I've got the code simply putting a comment in the console so I can see that it's worked for now.
[HttpPost]
public ActionResult UnlockUser(string userid)
{
if (userid != "")
{
return Json("success - call from HomeController", JsonRequestBehavior.AllowGet);
}
else
{
return Json("error", JsonRequestBehavior.AllowGet);
}
}
@Url.Action("UnlockUser", "Home")and then dodata: { userid : userid }