Reputation: 239
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 !
Upvotes: 2
Views: 17900
Reputation: 1079
$.ajax({
type: "post",
url: "/xyz/xyz",
data: "param1=" + value+ "¶m2=" + value,
});
i think it works, because i am using it and working with this
Upvotes: 0
Reputation: 12900
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.
Upvotes: 8
Reputation: 3358
Don't create query string on your own. Rely on jQuery:
$.ajax({
url: '/controller/method',
data: { startDate: startDate, endDate: endDate}
// ...
});
Upvotes: 12