Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 asp.net mvc 2 c#。我有一个动态表格。我想在我的控制器上从这个动态表单中获取字段。我怎样才能得到那些领域?
谢谢!
要么使用视图模型并将此视图模型传递给发布操作。当您说动态时,不清楚是否是未知的数字但结构始终相同,在这种情况下您可以使用视图模型的集合
[HttpPost] public ActionResult Index(IEnumerable<SomeViewModel> model) { ... }
或者,如果字段是完全任意且动态的,您可以使用Request控制器操作中的对象来读取它们的值。它是一个键/值集合,包含发送到控制器的所有内容。
Request