Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following controller to take four parameter and one to get an array of string.

public Response Get(string a, double b, double c, string[] d)
{
   do something
} 

As u see the fourth(d) parameter is an array of strings. The first 3 parameter get the value but d shows null.

I am using fiddler to debug with following url

04/api/Controller?a=Hello&b=-37.8031231&c=144.9836514&d=Italian&d=bars

What m i doing wrong? is it the url?

share|improve this question

2 Answers 2

Without seeing your View, I can abstract that you named 2 inputs as name='d' without indexing

example:

You can create an array by naming your id inputs with array indexes.

@using (Html.BeginForm())
{
    <input type="text" name="d[1]">
    <input type="text" name="d[2]">
}

If you index your inputs, the framework will use them as a List

Note: you bring up URL. You cannot pass an array or any complex object without a Post.

share|improve this answer
    
Thank you for taking time to reply. I dont have an index yet just a controller and m using fiddler. Thats a manually typed url.. So how should my url look like? i mean should i use /api/Controller?a=Hello&b=-37.8031231&c=144.9836514&d1=Italian&d2=bars –  Deeyo Feb 25 '13 at 5:59
    
@user2094169, you CANNOT pass an array to a controller with URL. You have to use a Form. –  Dave Alperovich Feb 25 '13 at 6:00
    
OIC, Thank for the tip. Goodday –  Deeyo Feb 25 '13 at 6:04
    
@user2094169, I altered my answer to include an example of a Razor form that would create an array. Would you be able to use this? –  Dave Alperovich Feb 25 '13 at 6:06

You can post array data from fiddler, the URL you have provided is correct. But make sure you have the correct content type in request header.

you don't have to create view to test your controller action method.

Client request

enter image description here

Server respone

enter image description here

P.S. Above provided is for controller action method, I have noticed you are using api controller after posting the answer. I will edit the answer once done for api controller.

The Above works for APIController as well, If you are posting from fiddler

share|improve this answer
    
This is interesting. Never used Fiddler. But in the end, he'll have to implement a real form anyway? –  Dave Alperovich Feb 25 '13 at 13:14
    
Don't have to wait till the view is developed to test the controller, There are also scenarios. Developer 1 create controller and its action method, Developer 2 create view and model in distributed development models :). –  Dilli Babu Feb 25 '13 at 14:22
    
That's pretty kool. I haven't used Fiddler yet. Seen many posts about it. Thanks. –  Dave Alperovich Feb 25 '13 at 14:27
    
It worked like a cheese cake. Thanks –  Deeyo Feb 26 '13 at 3:19
    
please mark it as answer if it worked, thanks in advance. –  Dilli Babu Feb 26 '13 at 3:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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