Yogesh Ghorpade

Yogesh Ghorpade

  • NA
  • 762
  • 148.1k

How To Call On Click Event Using J Query In MVC Application

Mar 15 2018 6:13 AM
How To Call Controllers Method Using J Query
 
I Have Tried This Code
 
View
 
<script>
function wronguser() {
debugger;
var obj = {};
$.ajax({
async: false,
type: "POST",
url: "Login/Cancel",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
debugger;
alert("Success");
},
error: function () {
alert("Failed to load ...!!!");
}
});
}
</script>
<input type="submit" value="Cancel" onclick="wronguser()" class="animated infinite pulse" style="background-color:#FFD540" />
 
Controller
 
[HttpPost]
public ActionResult Cancel()
{
return RedirectToAction("PageTwo", "MainPage");
}

Answers (2)