开发者

How to fetch an unknown number of POST parameters in ASP.NET MVC?

开发者 https://www.devze.com 2023-01-11 18:10 出处:网络
I have the following controller: class FooController : Controller { public ActionResult SomeAction(id) { Type t = Type.GetType(id);

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开发者_如何学Go were submitted.

How can it be done?


You do that with

[HttpPost]
public ActionResult SomeAction(id, FormCollection form)
{
    //do what you want with the collection
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消