2

I want to use:

$.ajax({url:'controller/method ?startDate=' +  startDate + '& endDate=' + endDate});

In the controller I have a method like this:

public PartialView GetChartDate(DateTime? startDate, DateTime? endDate){}

When I do this I end up passing null for endDate to the MVC method even though it has value. How do I pass multiple params to the MVC method?

Ideas and suggestions greatly appreciated !

3 Answers 3

12

Don't create query string on your own. Rely on jQuery:

$.ajax({
     url: '/controller/method',
     data: { startDate: startDate, endDate: endDate}
     // ...
});
1
  • This is probably the better method - less likely to make typos this way.
    – GregL
    Nov 16, 2011 at 23:40
8

If you actually cut-and-pasted your code, there's a space between the ampersand and the variable.

$.ajax({url:'controller/method ?startDate=' + startDate + '& endDate=' + endDate});
                                                            ^

Not sure if that is what does it, but check it out.

0
0
 $.ajax({
            type: "post",
            url: "/xyz/xyz",
            data: "param1=" + value+ "&param2=" + value,

        });

i think it works, because i am using it and working with this

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.