简体   繁体   English

如何使Html.EditorFor与复合objecs一起使用

[英]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. 我遇到样式困难,目前正在使用ASP MVC框架构建网站。 I am a big fan of the html.EditorFor option in the templates that generates a realy nice form for me. 我非常喜欢模板中的html.EditorFor选项,该选项为我生成了一个非常好的表单。 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. 我希望EditorFor函数生成一个不错的注册表单,询问姓名和地址数据,但是那时我似乎需要为每个类创建一个editortemplate。 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? 我需要什么设置才能使EditorFor生成适当的表单,而无需自己为每个表单创建模板?

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 同样,我不太介意需要创建那些表单,而只是希望系统为我做这种事情,以便我可以轻松地操作类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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