开发者

Azure: Get form field from View in my Controller

开发者 https://www.devze.com 2023-01-27 20:32 出处:网络
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?

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.

0

精彩评论

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