如何处理模型具有嵌套集合的强类型 MVC3 视图?
我有一个模型,其中有“问题”集合。每个问题都有一个“可能答案”的集合。可能的答案对象具有 isAnswer 属性,该属性应绑定到代表问题的所选单选按钮(在每个问题的组中)。
我是 MVC 新手,真的不确定如何构建视图,以便发布的模型将根据关联单选按钮的选择,收集每个问题的可能答案,其中一个对象的 isAnswer 属性设置为 true团体。
现在,视图应该为每个问题构建一个单选按钮组/列表,其中问题的可能答案集合代表与该问题相关的单选按钮选项。我可以在剃刀中做嵌套循环吗?你使用部分吗?当我发布它时,MVC 如何知道如何根据视图重建模型?
i have a model that has a Collections of "Questions". Each Question has a collection of "PossibleAnswers". The possible answer objects have an isAnswer property which should be bound to the selected radio button (in the group for each question) that represents the question.
I am new to MVC and really not sure how to build the view so that the posted model will have the collection of possibleanswers for each question with one of the objects having the isAnswer property set as true, based on the selection from the associated radio button group.
Right now the view should build a radio button group/list for each question with the possibleanswer collection of the question representing a radio button choice related to the question. Can i do nested loop in razor? do you use partials? how does MVC know how to rebuild the model based on the view when i post it??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其实很简单。棘手的部分是使用索引器
然后你的视图
It's actually very simple. The tricky part is to use indexers
Then your view