它是关于使用 MVC 2.0 的 ASP.NET 应用程序 artitecture
目前我正在开发 asp.net MVC-2 应用程序。我遇到了一个问题,如何将注册表单数据获取到控制器类中。有一个解决方案,我们可以使用 FormCollection 对象,但如何获取各个字段值。
有人可以帮忙吗?
Currently i am working on asp.net MVC-2 applications. i met with a problem that how to get signup form data into controller class. There is a solution that we can use FormCollection object but how to get individual field values.
Can anyone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理发布值的最简单方法是使用您提到的
FormCollection
对象。您可以像数组一样访问它:处理发布值的最佳方法是使用强类型视图模型。视图模型将包含表单的属性。如果可能的话,MVC 框架会自动将您的表单元素绑定到该对象。
因此,您的视图模型类可能如下所示:
如果您的 HTML 表单包含两个输入,其 name 属性设置为
Username
和Age
,那么您的可以修改控制器操作以使用刚刚描述的强类型视图模型:The simplest way to handle posted values is with the
FormCollection
object you mentioned. You can access it like an array:The best way to handle posted values is by using a strongly typed view model. The view model would contain properties of your form. The MVC framework will automagically bind your form elements to this object, if possible.
So, your view model class might look like:
If your HTML form contained two inputs with their name attributes set to
Username
andAge
, then your controller action could be modified to use the strongly types view model just described:去下载以下项目。有一个免费的 pdf 文档。完成整个样本。 了解的所有基础知识
它使您了解有关 ASP.NET MVC 框架Mvc Music Store
所需 在 Visual Studio 中创建一个默认的 MVC 项目,它应该向您展示如何在注册操作中处理注册表单。
Go and download the following project. There is a free pdf document. Work through the entire sample. It makes you understand all the basics you need to know about asp.net mvc framework
Mvc Music Store
And also if you create a default mvc project in visual studio, it should show you how to handle the signup form in the Register action.