1

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()        
    {
        //...
    }
} 
1
  • javascript will not convert your relative path to a real url. It does;t understand ~/. whatever you place in the ajax url parameter needs to be something that you could place in an anchor element's href attribute. Commented Feb 2, 2016 at 5:20

1 Answer 1

2

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.