tags:

views:

698

answers:

1

So I've return View(object);'d, and I press submit on that page, how do I get that object back in the controller? any ideas?

my viewpage is

public partial class Index : ViewPage<List<Models.Pricing>>

and

    public ActionResult Index(int id, FormCollection datesForm,
                             [Bind(Prefix="")]List<Pricing> model)
    {

        return View("Index", new{id});
    }
+2  A: 

Because you are really trying to retrieve a list of models (of type Pricing), you will either need to develop a custom IModelBinder and use it or iterate through the form collection and pull the data for each pricing model out of the form parameters and reconstitute them. Given your code, though, I don't see why you need to do this.

Is it really the case that you want to get the model data associated with the given id? Or is there more code than what you've shown? In the former case, the best thing to do is probably re-run the query using the id and not bother with the extra parameters to the controller action.

tvanfosson
Yeah, the list of prices are grabbed from a database so I'd rather get an object already populated with the information than run the query again, should I not bother?
Shahin
To not run the query again, you'll need to dump all the data for the objects into form inputs and then use the form inputs to create and populate the new objects. In your case, the best thing (I think) is to rerun the query.
tvanfosson
Thanks, I did what you recommended in the end.
Shahin