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

1 Comment

This is probably the better method - less likely to make typos this way.
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.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.