MVC 相当于中继器,具有多个表单元素和可供选择的复选框
我需要复制使用 asp 转发器获得的功能,该转发器包含 MVC 应用程序中的复选框、文本框和偶尔的下拉列表。在传统的 Web 表单中,您会收到一个回发事件,并且很容易获得与复选框(id)关联的所有控件及其值。
任何人都可以对如何在帖子中取回选中复选框的项目的值有任何好的建议。我能够在 FormCollection 中获取一些数组(甚至是强类型视图),但我无法找到有效链接值的好方法。
所有行都有一个复选框和一个文本框,某些行还有一个下拉列表
要进一步解释... 第 1 行有一个复选框和一个文本框 第 2 行有一个复选框、一个文本框和一个下拉列表。
如果用户选择第 1 行和第 2 行,我需要获取所有表单元素的值(用于某些计算)。另外,我还没有想出处理验证错误的好方法。
非常感谢任何建议。
I need to replicate the functionality you get with an asp repeater that contains checkboxes, textboxes, and the occasional dropdownlist in an MVC application. Om traditional webforms you get a postback event and its pretty easy to get at all the controls and their values associated with the checkbox (id).
Anybody have any good suggestions on how to get the values back on a post for the items that have the checkbox checked. I am able to get some arrays back in the FormCollection (and even a strongly typed view) but I have not been able to figure out a good way to link the values effectivly.
All rows have a checkbox and a textbox, some rows also have a dropdownlist
To further explain...
row 1 has a checkbox and a textbox
row 2 has a checkbox a textbox, and a dropdown list.
if the user selects row 1 and 2, I need to get the values for all the form elements (for some calculations). Also, I haven't come up with a good method of handling validation errors.
any suggestions are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的事情是迭代您将为其设置中继器的集合。使用 Razor 语法:
然后是一个控制器方法:
假设视图中的 Model 类型为 MyViewModel。了解其工作原理后,您可以查看 ASP.NET MVC 网格框架。
The simplest thing to do would be to iterate the collection for which you would have a repeater for. Using Razor syntax:
Then a controller method:
Assuming the the Model in the view is of type MyViewModel. Once you have a sense of how this works you can look into ASP.NET MVC grid frameworks.