1

HI,

i need to pass id=2 while calling the action method ? How can i pass id value to controller

http://localhost:52391/Campaign/Edit/2

{Controller}=Product {ActionMethod}=Action {id} =2

 function getProductDetails() {           
           var link = '**/Product/Details?callback=?**';                      
            $.ajax({
                url: link,
                data: {},
                dataType: "jsonp",
                jsonpCallback: "doextrawork"
            });

2 Answers 2

4
var link = '/Product/Details?callback=?';
$.ajax({
    url: link,
    data: { id: '<%= ViewContext.RouteData.Values["id"] %>' },
    dataType: "jsonp",
    jsonpCallback: "doextrawork"
 });
Sign up to request clarification or add additional context in comments.

2 Comments

data: { id: 2 }, i need to pass id dynamically from URL
@Aabb, then try like this: data: { id: '<%= ViewContext.RouteData.Values["id"] %>' }.
0

simply pass a json object with your id as a property.

$.ajax({
    url: link,
    data: {
        id: 2
    },
    dataType: "jsonp",
    jsonpCallback: "doextrawork"
});

1 Comment

data: { id: 2 }, i need to pass id dynamically from URL how can i

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.