mvc.net how to edit nested viewmodel classes

我的梦境 提交于 2019-12-06 22:32:32

Could you use an editor template here? Basically, you create a strongly typed partial view (Address is the type in your case), store it in a specific folder (/Views/Shared/EditorTemplates) and whenever an editor is rendered for a member of that data type, the partial view is automagically rendered instead. So, calling Html.EditorFor(model => model.mailingAddress) renders the partial view instead.

I think the first place I read about this was when I was looking for some DateTime validation. Check out this link, and maybe your partial view will have some Html.EditorFor(model => model.line1)'s and Html.EditorFor(model => model.city)'s

This does not make everything super-automatic, but it helps with the future editing of data types like Address.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!