tags:

views:

35

answers:

2

I have the following controller:

class FooController : Controller
{
  public ActionResult SomeAction(id)
  {
     Type t = Type.GetType(id);
     object o = Activator.CreateInstance(t);
     ((MyModel)o).ParseParamaters(PostParameters); // I need to pass the post parameters here
     //...
  }
}

I would like to fetch all the POST parameters that were submitted.
How can it be done?

+2  A: 

You do that with

[HttpPost]
public ActionResult SomeAction(id, FormCollection form)
{
    //do what you want with the collection
}
Joakim
The HttpPost attribute cannot be found. This is for MVC 2.I am using 1.1
the_drow
I changed the attribute to AcceptVerbs(HttpVerbs.Post)] and it worked. Thanks.
the_drow
+1  A: 

I believe Request.Querystring is just a collection of strings, so you could pass it as a parameter to ParseParameters. Or you could just pass the whole Request object.

But I'm wondering why you'd want to, when there's perfectly good model binding built into MVC to do all the heavy lifting for you. http://weblogs.asp.net/nmarun/archive/2010/02/25/asp-net-mvc-model-binding.aspx

mgroves
Because I can't tell which type is being created.
the_drow