tags:

views:

90

answers:

2

I am using javascript to append user selections to a list. When user is done , which is the best way to go:

1: create index for the list and submit as model in a form to the controller?

2: create hidden element and use javascript to append values and submit as actionlink? (not sure how to tell actionlink the value here)

3: wrap form block around the hidden element only and submit string as model?

other?

+1  A: 

I think the easiest way is to put some form of your list to the hidden field (type=hidden) and it will be automatically submitted with form and accessible on server under the name you gave it. So main reasoning here is the way you going to process these data on the server side.

dimarzionist
+1  A: 

First of all, Scott Hanselman has a good post about model binding to arrays, collections, etc.
In my opinion you shouldn't use second way because this will be a vulnerability ( description of CSRF).
In order to use collections binding you'll need to wrap a form around a list and submit it (note, this form will submit only selected values in this list but you may select them all before submit) or to create a map of values and submit it via javascript (for jQuery - $.post(url, data, callback)) or to add all pairs of name&value to some hidden element of a form and submit it.

zihotki