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

发布于 2024-10-12 13:07:01 字数 619 浏览 3 评论 0原文

我面临着风格困难,我目前正在使用 asp mvc 框架构建一个网站。我非常喜欢模板中的 html.EditorFor 选项,它为我生成了一个非常好的表单。因为我真的很讨厌自己对所有输入字段进行编程。然而,我对复合类的处理效果不佳。如果我有一个像这样的类:

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{
  ....
}

我希望 EditorFor 函数生成一个漂亮的注册表单,要求提供姓名和地址数据,但是我似乎需要为每个类制作一个编辑器模板。如果我决定换班级,那就太糟糕了。

我就在那里问你。有没有一个好的方法可以让这项工作发挥作用?我需要什么设置才能使 EditorFor 生成正确的表单,而无需自己为每个表单制作模板?

再说一遍,我不太介意我需要创建这些表单,我只是想让系统为我做这类事情,这样我就可以轻松地操作类

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文