简体   繁体   中英

How do I make Html.EditorFor work with composite objecs

I am faced with a style difficulty, I am currently building a site with the asp mvc framework. I am a big fan of the html.EditorFor option in the templates that generates a realy nice form for me. Because I really hate programming all the input fields myself. However I does not work as well with composite classes. If I have a class like:

public class person{
  public Address address { get; set; }
  public Name    name   { get; set; }
}

public class Address{
  public string street { get; set; }
  public string zipcode { get; set; }
  ....
}
public class Name{
  ....
}

I would like the EditorFor function to generate a nice registration form asking for the name and address data however I seem to need to make a editortemplate for every class then. Which is nasty if i ever decide to change the class.

There for I am asking you. Is there a nice way to make this work? What setting do I need to make EditorFor generate the proper form without needing to make a template for every form myself?

Again I don't mind it to much that i need to create those forms I would just rather have the system do that kind of stuff for me so that I can easily manipulate classes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM