Create Views for object properties in model in MVC 3 application?

后端 未结 2 394
一个人的身影
一个人的身影 2021-01-24 01:59

I have an Asp.Net MVC 3 application with a database \"Consultants\", accessed by EF. Now, the Consultant table in the db has a one-to-many relationship to several other tables f

相关标签:
2条回答
  • 2021-01-24 02:14

    Phil Haack has written a great blog post which explains how to model bind to a list. It's specific to MVC2, but I'm not sure if version 3 has improved on this.

    Model Binding To A List.

    In a scenario where the user is allowed to add an arbitrary number of items, you'll probably want to create new input fields using JavaScript. Steven Sanderson shows here how to achieve that:

    Editing a variable length list, ASP.NET MVC 2-style.

    Those resources should get you all the way there.

    0 讨论(0)
  • 2021-01-24 02:35

    You may take a look at the following blog post about writing custom object templates. Also don't use EF models in your views. Design view models that are classes specifically tailored to the needs of a given view and have your controller map between the EF models and the view models that should be passed to the view. AutoMapper is a good tool that could simplify this mapping.

    0 讨论(0)
提交回复
热议问题