帮助创建视图和更新实体模型
编辑:这个问题很模糊,可能对任何人都没用。我正在将互联网资金奖励给“帮助”我的下面的先生。
抱歉,标题有点模糊。我对 ASP MVC 和 ASP 还很陌生。 EF。这是我的问题。我有一个类似这样的数据库。
Employee
- ID
- Name
- Address
EmployeeJob
- EmployeeID
- JobID
- StartDate
JobTypes
- ID
- JobName
我想要一个创建表单,该表单将显示所有员工字段以及供用户选择的工作类型列表。然后我将结果发送回控制器并更新数据库。我已经开始研究自定义视图模型,但仍然不确定如何将其组合在一起并使其发挥作用。谢谢,
EDIT: This question is vague and will likely be of little use to anyone. I am awarding internet monies to the gentleman below whom "helped" me.
Sorry that the title is a little vague. I am still new to asp mvc & EF. Here is my issue. I have a DB somewhat like this.
Employee
- ID
- Name
- Address
EmployeeJob
- EmployeeID
- JobID
- StartDate
JobTypes
- ID
- JobName
I want a create form that will show all the Employee fields as well as a list of JobTypes for the users to be able to select. Then I will post the results back to the controller and update the DB. I have started looking into custom viewmodels, but am still unsure of exactly how to put that together and get it to work. Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个特定的视图模型,反映视图显示界面所需的数据。在本例中,员工信息加上当前关系所代表的职位集合。添加显示作业菜单所需的信息——在本例中,我将使用 SelectListItems 的枚举(值 = ID,文本 = JobName)。
根据您想要执行的操作,您可能需要不同的帖子模型。
或者(这可能需要在视图模型中使用不同的 JobTypes 集合)
使用视图模型提供的数据,使用输入名称设置表单以反映回发的模型。
Create a specific view model that reflects the data needed by the view to display the interface. In this case, the employee information plus the collection of jobs represented by the current relations. Add to that the information required to show the jobs menu -- in this case I'd use an enumeration of SelectListItems (Value = ID, Text = JobName).
Depending on what you are trying to do you might want a different model for the post.
or (this might argue for a different collection for JobTypes in the view model)
Set up your form with input names to reflect the model being posted back, using the data supplied by the view model.