Reputation: 403
I am trying to call a void method in my Controller when I click on a Button using Ajax. But when I do so nothing happens. It does not hit the Controller method.
This is my View:
<td>
<span class="leftalign">
<input type="submit" id="myButton" value="Picked Output" />
</span>
</td>
<script>
$("#myButton").click(function(e){
e.preventDefault();
var rootUrl = "~/Report/";
$.ajax({
//url: $(this).attr("href"),
url: rootUrl + "Picksapout/pickssap",
success: function(){
alert("#");
}
});
});
</script>
My Controller Void Method:
public class PicksapoutController : MasterController
{
private void pickssap()
{
//...
}
}
Upvotes: 1
Views: 2555
Reputation:
Generate your url correctly using
url: '@Url.Action("pickssap", "Picksapout")',
But your method should is private
and will never be hit. Change it to be
public ActionResult pickssap()
Upvotes: 2