asp.net mvc + activerecord保存对象图
我正在使用 asp.net mvc,我正在尝试创建一个新的员工,在我的表单中,我使用 Html.DropDown(...) 来显示可供选择的部门列表。
理想情况下,我希望 MVC 找出选择了哪个部门(Id 属性是下拉列表中的值),获取它并将其设置在传入的 Employee 对象中。 相反,我得到一个 null 值,并且我必须使用 Request.Form[...] 自己获取部门。
我在这里看到一个例子: http://blog.rodj.org/archive/2008/03/31/activerecord-the-asp.net-mvc-framework.aspx 但这似乎不适用于 asp.net mvc beta
这是带有经过充分验证的 ORM 的基本 CRUD...真的需要这么难吗?
I'm using asp.net mvc and I'm trying to create a new Employee, in my form I use the Html.DropDown(...) to display a list of Departments to select from.
Ideally I would like MVC to just figure out which Department was selected (Id property is the value in dropdown), fetch it and set it in the incoming Employee object. instead I get a null value and I have to fetch the Department myself using the Request.Form[...].
I saw an example here: http://blog.rodj.org/archive/2008/03/31/activerecord-the-asp.net-mvc-framework.aspx but that doesn't seem to work with asp.net mvc beta
This is basic CRUD with a well-proven ORM.... need it really be so hard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET MVC 不知道如何将 DepartmentId 表单值转换为 Department.Load(DepartmentId) 调用。 为此,您需要为您的模型实现绑定器。
EmployeeBinder 负责将路由/表单数据转换为对象。
有了这个,只要将 Employee 用作操作的参数,就会调用活页夹。
请参阅 此博文了解更多信息
ASP.NET MVC does not know how to translate the DepartmentId form value to a Department.Load(DepartmentId) call. To do this you need to implement a binder for your model.
The EmployeeBinder is responsible for turning route/form data into an object.
With this in place anytime an Employee is used as a parameter for an action the binder will be called.
See This blog post for further information
我将 ARFetch 移植到 ASP.NET MVC几周前...也许这可以帮助你。
I ported ARFetch to ASP.NET MVC a couple of weeks ago... maybe that could help you.