MVC2 FormCollection 选项
我刚刚开始使用 MVC2 并浏览 NerdDinner 示例。我注意到似乎有多种方法可以传递表单值,例如:
FormColelction formvalues
FormCollection collection
FormCollection form
为什么要使用一种而不是另一种,为什么? 这是否也与您是否使用实体框架有关?
I'm just getting started with MVC2 and going through the NerdDinner examples. I noticed that there seems to be multiple ways to pass in the form values for example:
FormColelction formvalues
FormCollection collection
FormCollection form
Why would you use one over the other and why?
Does it also relate to whether you are using Entity Framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面的每个示例都传递相同的类型 (FormCollection),但变量名称不同。
如果 NerdDinner 能保持一定的一致性那就太好了。
您还可以让 MVC 自动从表单填充自定义对象,而不是使用通用 FormCollection。
EG 如果您发布的表单包含名字、姓氏和年龄(代表一个人)字段,您可以使用类似的方法
Each of the above examples is passing in the same type (FormCollection) but with just a different variable name.
It would have been nice to see some consistency in NerdDinner.
You can also have MVC automagically populate a custom object from your form instead of using the generic FormCollection.
EG If your form being posted has fields for FirstName, LastName and Age (representing a person) you could have a method like