如何使 Html.EditorFor 与复合对象一起使用
我面临着风格困难,我目前正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 Brad Wilson 关于“深入研究”模板的博客:
http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html
See Brad Wilson blog on 'deep diving' templates:
http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html