Using asp.net mvc 2 c#. I开发者_StackOverflow have a dynamic form. I want to get fields from this dynamic form at my controller. How can I get that fields?
Thanks!
Either use a view model and pass this view model to the post action. When you say dynamic it is not clear whether it's the number that is not known but the structure always the same in which case you could use a collection of a view model
[HttpPost]
public ActionResult Index(IEnumerable<SomeViewModel> model)
{
...
}
or if the fields are totally arbitrary and dynamic you could use the Request
object inside your controller action to read their values. It is a key/value collection containing everything that is sent to the controller.
精彩评论