I'm using ajax and trying to pass the Model back, which is a generic List < T >. I tried Model.ToList() but I don't think I'm going about this correctly. I think it is already setup but I just need to find the method or property name to get the List that was posted, which might not work since my Model from the controller contains a couple of lists to pass to different partials and one of these partials, I'm trying to update the partial view. I'm basically trying to sort the list. So using an AJAX to call the controller but I need the list to sort and call the partial again. I hope my explanation wasn't too confusing.
A:
If these are just single values you are passing back, such as int, strings, floats, etc. You can just put the array in the action like so:
public ActionResult MyAction (int id, string[] value)
Or you can use something called a FormCollection
public ActionResult MyAction (int id, FormCollection form) {
string[] values = form.GetValues("value");
Or you can use Request.Form (this is not recommended, because the above two are more recommended
public ActionResult MyAction(int id) {
string[] values = Request.Form.GetValues("value");
Hope this helps. I didn't totally understand what your question was, but it seemed to be dealing with how to get an array of posted values.
Nick Berardi
2009-07-12 23:29:44
how would i pass the form variable from my ajax call? form = ?Thanks
Bruce227
2009-07-12 23:38:02
No FormCollection is a special case. It is just an alternative to calling Request.Form. So FormCollection will contain all post back information, while also allowing you to use standard unit tests.
Nick Berardi
2009-07-13 12:44:52