2

I need to send a list of strings to a method in a controller in asp net mvc. How can I do this?

I want my method in my controller to look something like this:

public ActionResult CutFile(string[] filenames, string target)

Optionally I can change the string array parameter to something like this:

public ActionResult CutFile(IEnumerable<string> filenames, string target)

1 Answer 1

3

You need to send the data in this format:

<input type="text" name="filenames[0]" value="A"/>
<input type="text" name="filenames[1]" value="B"/>
<input type="text" name="filenames[2]" value="C"/>

<input type="text" name="target" />
Sign up to request clarification or add additional context in comments.

2 Comments

what if I am using jquery with ajax to do a post to the method, how would I do that?
just pass a list of string: {filenames: ['A','B','C'], target: 'X'}

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.